-1

我有 2 个图片框,我只想将它们导出为 1 张图片。我只需要以它们的状态导出它们,而不是创建 .bmp。我尝试将其作为表单的屏幕截图,但问题是有时图片比表单大,屏幕截图仅截取表单可见的部分,我该怎么办?

这是屏幕截图的代码示例

MenuStrip1.Hide()
    Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
    ' Create a graphics object from the bitmap  
    Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
    ' Take a screenshot of the entire Form1  
    gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
    ' Save the screenshot  
    SaveFileDialog1.ShowDialog()
    SaveFileDialog1.Filter = "Image files (*.PNG)|*.PNG|(*.JPG*)|*.JPG*"
    bmpScreenshot.Save(SaveFileDialog1.FileName)
    MenuStrip1.Show()
4

1 回答 1

0

以下是 PictureBox1 作为“背景”和 PictureBox2 作为 PictureBox1“顶部”的较小图像时的样子:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    SaveFileDialog1.Filter = "Image files (*.PNG)|*.PNG|(*.JPG*)|*.JPG*"
    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
        Dim bmp As New Bitmap(PictureBox1.Image.Width, PictureBox1.Image.Height)
        Using G As Graphics = Graphics.FromImage(bmp)
            G.Clear(Color.Black)
            G.DrawImage(PictureBox1.Image, New Point(0, 0))
            G.DrawImage(PictureBox2.Image, PictureBox2.Location)
        End Using
        Select Case System.IO.Path.GetExtension(SaveFileDialog1.FileName).ToUpper
            Case ".PNG"
                bmp.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png)
            Case ".JPG"
                bmp.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
        End Select
    End If
End Sub
于 2013-07-14T00:59:30.873 回答