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 : 14064
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



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



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
...

{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
Une loupe agrandissant une image réduite aux dimensions de l’écran Ayant été confronté a afficher d...

{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...

{Visual Basic, VB6, VB.NET, VB 2005} USERCONTROL PERMETTANT D'AFFICHER UNE CARTE (OU N'IMPORTE QUELLE IMG) ET DE PLACER DES POINTS D'INTÉRET MOBILES
Bonjour, je me suis mis à VB.net depuis une semaine, voici ma première contribution. Il s'agit d'...

{C# / C#.NET} CAPTURER UNE IMAGE DEPUIS UNE WEBCAM
Bonjour tous le monde, comme je cherchais une source permettant de capturer une image depuis une web...

{Javascript / DHTML} CONTRÔLE DES CHAMPS D'UN FORMULAIRE [CCF]
les contrôles à effectuer sont décrits dans un .xml ...

{Javascript / DHTML} PETIT SCRIPT MAIS EFFICACE POUR VALIDER LES DATES
ce code permet de valider une date si elle est conforme au calendrier, elle retourne un booléen, exe...

{Flash} CONTROLE DU FLOOD VIA FLASH ET SHARE OBJECT
Voici une classe permettant de faire un controle du flood via flash. Avec la particularité de contro...