0

在这里寻求帮助,我有一个名为 PB1 的透明图片框(使用紫红色作为透明度键),其中 PB1.Location.X = 145,PB1.Location Y = 7 和一个名为 btnTakePic 的按钮。代码如下:

    Private Sub btnTakePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTakePic.Click
    Dim Bound As Rectangle
    Dim Pic As Graphics
    Dim screenshot As System.Drawing.Bitmap
    Bound = Screen.PrimaryScreen.Bounds
    screenshot = New System.Drawing.Bitmap(PB1.Bounds.Width, PB1.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
    Pic = Graphics.FromImage(screenshot)
    Pic.CopyFromScreen(CInt(LocPBX.Text), CInt(LocPBY.Text), 0, 0, Bounds.Size, CopyPixelOperation.SourceCopy)
    PB1.Image = screenshot
    PB1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub

Private Sub Main_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
    LocX.Text = Me.Location.X
    LocY.Text = Me.Location.Y
    LocPBX.Text = Val(PB1.Location.X) + Val(LocX.Text) + 3
    LocPBY.Text = Val(PB1.Location.Y) + Val(LocY.Text + 25)
End Sub

现在的问题是:它生成的截图正是我想要的,但是当我点击 btnTakePic 时,图片将与旧图片重叠,我想从内存中删除旧图片截图并用新图片替换,怎么办那 ?

4

1 回答 1

1

在拍摄新照片之前清除之前的图像并刷新图片框:

Private Sub btnTakePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTakePic.Click
    PB1.Image = Nothing
    PB1.Refresh()

    Dim pt As Point = PB1.PointToScreen(New Point(0, 0))
    Dim screenshot As New System.Drawing.Bitmap(PB1.Size.Width, PB1.Size.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
    Using Pic As Graphics = Graphics.FromImage(screenshot)
        Pic.CopyFromScreen(pt.X, pt.Y, 0, 0, PB1.Size, CopyPixelOperation.SourceCopy)
    End Using
    PB1.Image = screenshot
    PB1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub

但是,如果您已经显示了屏幕截图,您怎么知道您正在拍摄什么?

于 2013-06-06T17:23:40.627 回答