Les Snippets

Connexion

Capture de l'image d'une form et de tous ses contrôles

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 06/05/2006 20:31:48 et initié par Charles Racaud [Liste]
Date de mise à jour : 27/05/2006 12:53:37
Vue : 28082
Catégorie(s) : Graphique
Langages dispo pour ce code :
- VB 2005
- C# 2.x
- C# 1.x, C# 2.x
- Delphi 5
- Windev
- VB 2005, VB.NET 1.x
- VB6
- Delphi 5



Langage : VB 2005
Date ajout : 06/05/2006
Posté par Charles Racaud [Liste]
DateMAJ : 07/05/2006
Dim TargetImg As New System.Drawing.Bitmap(MyBase.Size.Width, MyBase.Size.Height)
MyBase.DrawToBitmap(TargetImg, New System.Drawing.Rectangle(0, 0, MyBase.Size.Width, MyBase.Size.Height))
Langage : C# 2.x
Date ajout : 06/05/2006
Posté par Charles Racaud [Liste]
DateMAJ : 07/05/2006
System.Drawing.Bitmap TargetImg = new System.Drawing.Bitmap(base.Size.Width, base.Size.Height);
base.DrawToBitmap(TargetImg, new System.Drawing.Rectangle(0, 0, base.Size.Width, base.Size.Height));
Langage : C# 1.x , C# 2.x
Date ajout : 07/05/2006
Posté par MorpionMx [Liste]
private const int WM_PRINT = 0x0317;
private const int PRF_CLIENT = 0x00000004;
private const int PRF_CHILDREN = 0x00000010;

public Bitmap PrintWindowEx()
{
   Bitmap bmp = null;
   Graphics gr = null;
   IntPtr hdc = IntPtr.Zero;
   try
   {
      bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, this.CreateGraphics());
      gr = Graphics.FromImage(bmp);
      hdc = gr.GetHdc();
      IntPtr wParam = hdc;
      IntPtr lParam = new IntPtr(PRF_CLIENT | PRF_CHILDREN);
      Message msg = Message.Create(this.Handle, WM_PRINT, wParam, lParam);
      this.WndProc(ref msg);
      }
      catch { }
      finally
      {
         if (gr != null)
         {
            if (hdc != IntPtr.Zero)
               gr.ReleaseHdc(hdc);
            gr.Dispose();
         }
      }
   return bmp;
}
Langage : Delphi 5
Date ajout : 12/08/2006
Posté par cirec [Liste]

Procedure Make_Shoot(aForm : TForm; aBmp : TBitmap);
Var aDc : HDC;
Begin
  If (aForm = Nil) or (aBmp = Nil) Then Exit;
  With aBmp do
  Begin
    Height := aForm.Height;
    Width  := aForm.Width;
    aDC    := GetWindowDC(aForm.Handle);
    BitBlt(Canvas.Handle, 0, 0, Width, Height, aDC,
      0, 0, srcCopy);
    ReleaseDC(aForm.Handle, aDC);
  End;
End;

// Utilisation
procedure TfrmMain.btn_ShootClick(Sender: TObject);
Var Bmp : TBitmap;
begin
  Bmp := TBitmap.Create;
  Make_Shoot(Self, Bmp);
  // ... ici votre code pour enregistrer où afficher l'image ...
  Bmp.Free;
end;


Langage : Windev
Date ajout : 13/08/2006
Posté par Elian Lacroix [Liste]
// Une fonction place le contenu de la fenêtre en cours sous 
// forme graphique dans un champ image
dCopieImage(copieEcran,MonImage)
// Il est alors possible de conserver l'image sur disque
dSauveImageJPEG(MonImage, "C:\Temp\Image.jpg")

Langage : VB.NET 1.x , VB 2005
Date ajout : 21/08/2006
Posté par Charles Racaud [Liste]
Private Const WM_PRINT As Integer = &H317
Private Const PRF_CLIENT As Integer = &H4
Private Const PRF_CHILDREN As Integer = &H10
Public Function PrintControl(ByVal Ctrl As System.Windows.Forms.Control) As System.Drawing.Bitmap
  Dim bmp As System.Drawing.Bitmap = Nothing
  Dim gr As System.Drawing.Graphics = Nothing
  Dim hdc As IntPtr = IntPtr.Zero
  Try
    bmp = New System.Drawing.Bitmap(Ctrl.ClientRectangle.Width, Ctrl.ClientRectangle.Height, Ctrl.CreateGraphics())
    gr = Graphics.FromImage(bmp)
    hdc = gr.GetHdc()
    Dim wParam As IntPtr = hdc
    Dim lParam As IntPtr = New IntPtr(PRF_CLIENT Or PRF_CHILDREN)
    Dim msg As System.Windows.Forms.Message = System.Windows.Forms.Message.Create(Ctrl.Handle, WM_PRINT, wParam, lParam)
    MyBase.WndProc(msg)
  Catch
  Finally
    If Not gr Is Nothing Then
      If hdc <> IntPtr.Zero Then gr.ReleaseHdc(hdc)
      gr.Dispose()
    End If
  End Try
  Return bmp
End Function
Langage : VB6
Date ajout : 22/08/2006
Posté par EBArtSoft [Liste]

Private Declare Function PrintWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long

PrintWindow Form1.hWnd, DestinationDC, 0


Langage : Delphi 5
Date ajout : 12/02/2009
Posté par cirec [Liste]
Function PrintWindow(ahwnd:HWND; hdcBlt:HDC;  nFlags:UINT): Bool; Stdcall; External 'User32.dll'  name 'PrintWindow'; 
Implementation 
Uses testwnd; { juste pour tester le code } 
{$R *.dfm} 
  // Prend un  instantané du hwnd de la fenêtre, 
  //  stocké dans le contexte de périphérique hdcMem de la mémoire  
  // cette méthode fonctionne même si la fenêtre  n'est pas 
  // en avant plan ou se trouve  en dehors de la zone écran 
Function  GetFullWindowImage(aHandle : THandle):TBitmap; 
Var DC, hdcMem : HDC; 
    aRect : TRect;  
    hBMP : HBitmap; 
    aWidth, aHeight : Integer; 
Begin 
  Result := Nil; 
  dc := GetWindowDC(0); 
  If (dc >  0) Then 
  Try  
    hdcMem := CreateCompatibleDC(dc); 
    If (hdcMem > 0) Then 
    Try 
      GetWindowRect(aHandle,  aRect); 
      aWidth := aRect.Right-aRect.Left; 
      aHeight :=  aRect.Bottom-aRect.Top; 
      hBMP := CreateCompatibleBitmap(dc, aWidth,  aHeight); 
      If (hBMP > 0) Then 
      Try  
        SelectObject(hdcMem, hBMP);  
        PrintWindow(aHandle, hdcMem, 0);  
        Result := TBitmap.Create; 
        Result.Width := aWidth;  
        Result.Height := aHeight; 
        BitBlt(Result.Canvas.Handle,  0, 0, aWidth, aHeight,  hdcMem, 0, 0, srcCopy);  
      Finally  
        DeleteObject(hBMP); 
      End; 
    Finally  
      DeleteObject(hdcMem); 
    End; 
  Finally  
    ReleaseDC(0, dc); 
  End; 
End;  
{ exemple d'utilisation} 
Procedure TForm1.Button3Click(Sender: TObject);  
Var FormImage : TBitmap; 
Begin 
  FormImage :=  GetFullWindowImage(testfrm.Handle); 
  Try  
    Image1.Picture.Bitmap.Assign(FormImage); 
  Finally 
    FormImage.Free; 
  End; 
End; 


Remarque :
Cette méthode fonctionne même si la fenêtre n'est pas
en avant plan ou se trouve en dehors de la zone écran

Snippets en rapport avec : Capture, Image, Controle, Picture, Formulaire



Codes sources en rapport avec : Capture, Image, Controle, Picture, Formulaire

{JAVA / J2EE} FAIRE DEFILER UNE IMAGE
...

{Visual Basic, VB6, VB.NET, VB 2005} MERGEIMAGES
Assembler 2 images pour n'en faire qu'une. Vous ouvrez 2 images de même hauteur en pixel et de même ...

{Visual Basic, VB6, VB.NET, VB 2005} SAVEPICTURE() AU FORMAT PNG, JPG, TIF ETC...
Bonjour, Quelqu'un m'a dit l'autre jour "Enregistrer une image en PNG avec SavePicture en VB6 c'e...

{JAVA / J2EE} [CONCOURS ANDROID] PHOTOTHÈQUE
Photothèque vous permet de visualiser toutes les photos de votre carte SD et de les afficher en plei...

{PHP} CLASSE : GÉNÉRATEUR DE MINIATURE STRICTE OPTIMISÉ
Bonjour, Une classe qui permet de générer une miniature (à partir d'un formulaire d'envoi) avec d...

{Visual Basic, VB6, VB.NET, VB 2005} AFFICHER UNE IMAGE DANS UNE CELLULE D'UN DATAGRIDVIEW LIÉ À UN DATASET
Cette classe personnalise une colonne d'un datagridview pour afficher une image dans une cellule en ...

{PHP} CRÉE UNE IMAGE DE PILE DE MINIATURES EN UTILISANT LA BIBLIOTHÈQUE GD
Tout est dans le titre. Regarder la capture pour mieux comprendre. N'hésitez pas à me contacter ...

{Visual Basic, VB6, VB.NET, VB 2005} LOUPE PICTURE BOX
AUTEUR: ProgElecT SOURCE: http://www.developpez.net/forums/d208213/autres-langages/general-visual...

{PHP} FUNCTION CAPTCHA
Cette fonction permet de créer une image PNG contenant des caractères générés de façon aléatoire. ...

{Visual Basic, VB6, VB.NET, VB 2005} CAPTURE GRAPHIQUE DU CONTENU D'UN CONTRÔLE DONNÉ DANS UNE IMAGE SAUVÉ SUR DISQUE PUIS DÉCOUPÉE POUR IMPRESSION
Dans le projet que je suis en train de mener à bien, je dessine des plans de baies informatiques con...