保存图片框的图像

时间:2017-04-11 08:14:09

标签: vb.net picturebox

所以我有这段代码:

Private Sub button28_Click(sender As Object, e As EventArgs) Handles button28.Click
    Dim bounds As Rectangle
    Dim screenshot As System.Drawing.Bitmap
    Dim graph As Graphics
    bounds = PicOuterBorder.Bounds
    screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    graph = Graphics.FromImage(screenshot)
    graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
    picFinal.Image = screenshot
    'this takes a screenshot
End Sub 

PicOuterBorder是我表单上的图片框。 PicFinal是另一个显示图片框。但是这段代码让我知道了这一点:...这基本上是从屏幕原点开始的PicOuterBorder大小的窗口截图。但是,Me.Bounds代替PicOuterBorder.Bounds可以正常工作,并获得仅仅是我的表单的完美屏幕截图。我希望picFinal有一个PicOuterBorder的截图

2 个答案:

答案 0 :(得分:1)

根据以下内容调整代码:

Public Sub SaveImage(filename As String, image As Image, Encoder As ImageCodecInfo, EncParam As EncoderParameter)

Dim path As String = System.IO.Path.Combine(My.Application.Info.DirectoryPath, filename & ".jpg")
Dim mySource As New Bitmap(image.Width, image.Height)
Dim grfx As Graphics = Graphics.FromImage(mySource)
grfx.DrawImageUnscaled(image, Point.Empty)
grfx.Dispose()
mySource.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg)
mySource.Dispose()

End Sub

答案 1 :(得分:1)

尝试以下代码。您必须使用 <tr onclick="doSomething()"> <td>text</td> <td>text</td> <td>text</td> <td onclick="doSomethingElse(); event.stopPropagation(); "> <!-- drop down elements --> </td> </tr> 将控件坐标映射到屏幕坐标。我已将PointToScreen放在面板PicOuterBorder中。 PanelPicture没有任何边框,而PanelPicture可以有任何类型的边框样式。下面的代码拍摄了面板的快照。

PicOuterBorder