简体   繁体   English

如何获取截图,仅适用于图片框

[英]How to get a screenshot, only for a picturebox

I used so many pictureboxs to make 1 image, now I want to take a screen of it so I can save it. 我使用了很多图片框来制作1张图片,现在我想对其进行屏幕显示以保存它。 I just copied this code from Msn, and edited a bit, but it doesn't work. 我只是从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

Updated solution: 更新的解决方案:

    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

Try this: 尝试这个:

    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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM