我使用了很多图片框来制作1张图片,现在我想拍一张它的屏幕,这样我就可以保存它。我刚刚从Msn复制了这段代码,并进行了一些编辑,但它并没有起作用。
Dim myGraphics As Graphics = PictureBox1.CreateGraphics()
Dim s As Size = PictureBox1.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(PictureBox1.Location.X, PictureBox1.Location.Y, 0, 0, s)
PictureBox2.Image = memoryImage
答案 0 :(得分:1)
更新了解决方案:
Dim s As Size = PictureBox1.Size
Dim memoryImage = New Bitmap(s.Width, s.Height)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
Dim ScreenPos As Point = Me.PictureBox1.PointToScreen(New Point(0, 0))
memoryGraphics.CopyFromScreen(ScreenPos.X, ScreenPos.Y, 0, 0, s)
PictureBox2.Image = memoryImage
答案 1 :(得分:0)
试试这个:
Dim desktopSize As Size
desktopSize = System.Windows.Forms.SystemInformation.PrimaryMonitorSize
Dim height As Integer = desktopSize.Height
Dim width As Integer = desktopSize.Width
PictureBox1.Left = 0
PictureBox1.Top = 0
PictureBox1.Width = width
PictureBox1.Height = height
PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage 'To test that region has captured
Dim memoryImage As Bitmap
Dim myGraphics As Graphics = PictureBox1.CreateGraphics()
Dim s As Size = PictureBox1.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(PictureBox1.Location.X, PictureBox1.Location.Y, 0, 0, s)
PictureBox2.Image = memoryImage