Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _ hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _ Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _ hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _ ByVal dwRop As System.Int32) As Long
Dim memoryImage As Bitmap
Private Sub CaptureScreen() Dim mygraphics As Graphics = Me.CreateGraphics() Dim s As Size = Me.Size memoryImage = New Bitmap(s.Width, s.Height, mygraphics) Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage) Dim dc1 As IntPtr = mygraphics.GetHdc Dim dc2 As IntPtr = memoryGraphics.GetHdc BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, dc1, 0, 0, 13369376) mygraphics.ReleaseHdc(dc1) memoryGraphics.ReleaseHdc(dc2) PictureBox1.Image = memoryImage ' ici que picturebox contient le résultat End Sub
CaptureScreen()
PictureBox1.Image.Save("fichiercapture.bmp")
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, dc1, 0, 0, 13369376)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub CommandButton4_Click() Private Declare Function BitBlt Lib "gdi32.dll" (ByVal _ hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _ Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _ hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _ ByVal dwRop As System.Int32) As Long Dim memoryImage As bitmap 'capture d'écran Dim mygraphics As Graphics mygraohics = UserForm3.CreateGraphics() '' ici , c'est pas mygraohics ''mais mygraphics Dim s As Size s = UserForm3.Size memoryImage = New bitmap(s.width,s.height,mygraphics) Dim memoryGraphics As Graphics memoryGraphics = Graphics.FromImage(memoryImage) Dim dc1 As IntPtr dc1 = mygraphics.GetHdc Dim dc2 As IntPtr dc2 = memoryGraphics.GetHdc BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, dc1, 0, 0, 13369376) mygraphics.ReleaseHdc (dc1) memoryGraphics.ReleaseHdc (dc2) PictureBox1.Image = memoryImage ' ici que picturebox contient le résultat PictureBox1.Image.Save ("fichiercapture.bmp") End Sub
Public Class Form1 Private Declare Function BitBlt Lib "gdi32.dll" (ByVal _ hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _ Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _ hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _ ByVal dwRop As System.Int32) As Long Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim memoryImage As Bitmap 'capture d'écran Dim mygraphics As Graphics mygraphics = Me.CreateGraphics() '' faute de frappe '' userform3 Dim s As Size s = Me.Size '' userform3 memoryImage = New Bitmap(s.Width, s.Height, mygraphics) Dim memoryGraphics As Graphics memoryGraphics = Graphics.FromImage(memoryImage) Dim dc1 As IntPtr dc1 = mygraphics.GetHdc Dim dc2 As IntPtr dc2 = memoryGraphics.GetHdc BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, dc1, 0, 0, 13369376) mygraphics.ReleaseHdc(dc1) memoryGraphics.ReleaseHdc(dc2) PictureBox1.Image = memoryImage ' ici que picturebox contient le résultat PictureBox1.Image.Save("fichiercapture.bmp") End Sub End Class
Dim b As New Bitmap(Me.Width, Me.Height) Me.DrawToBitmap(b, New Rectangle(0, 0, Me.Width, Me.Height)) b.Save(Application.StartupPath & "\maform.jpg", Imaging.ImageFormat.Jpeg)