在Overlapping Screenshot图像上需要帮助

时间:2013-06-06 12:15:48

标签: vb.net visual-studio-2008

在这里寻求帮助,我有一个透明的图片框(使用fucshia作为transparencyKey)名为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时,图片将与旧图片重叠,我想从内存中删除旧图片截图并用新的替换它,怎么做?

1 个答案:

答案 0 :(得分: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

如果你已经有截图显示,你怎么知道你拍的是什么?