Vb.net 保存picturebox的图像
所以我有这个代码:Vb.net 保存picturebox的图像,vb.net,picturebox,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 Sy
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
PicouterOrder
是我表单上的一个图片盒PicFinal
是另一个显示图片框。但这段代码让我明白了这一点:它基本上是一个屏幕截图,从屏幕的原点开始,大小为PicouterOrder。但是,Me.Bounds
而不是PicOuterBorder.Bounds
可以正常工作并获得一个完整的屏幕截图。我想让picFinal有一个PicOuterOrder的屏幕截图使您的代码适应如下内容:
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
试试下面的代码。您必须使用
指向屏幕
将控制坐标映射到屏幕坐标。我已将PicOuterBorder
放置在面板PanelPicture
内PanelPicture
没有任何边框,而PicOuterOrder
可以有任何类型的边框样式。下面的代码拍摄了面板的快照
Private Sub button28_Click(sender As Object, e As EventArgs) Handles button28.Click
Dim graph As Graphics = Nothing
Dim bounds As Rectangle = Nothing
Dim screenshot As System.Drawing.Bitmap
Dim location As Drawing.Point = PanelPicture.PointToScreen(Drawing.Point.Empty)
screenshot = New System.Drawing.Bitmap(PanelPicture.Width, PanelPicture.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(location.X, location.Y, 0, 0, PanelPicture.Size, CopyPixelOperation.SourceCopy)
picFinal.Image = screenshot
graph.Dispose()
End Sub
但首先,我需要调整自己来理解你说的话。请澄清一下。