在visual basic中刷新picturebox图像

时间:2014-09-26 02:09:13

标签: vb.net

我正在编写一个编辑图片的程序,我有一个图片框,我加载一个位图,第一个图像加载正常,但如果我想加载第二个图像,第二个图像将无法加载,第一个图像停留,它不会刷新。如何使用2个不同的位图更改图片框中的图像?

我有PictureBox3.Image = bm其中bm是位图变量,它加载正常,但是如果我按下另一个按钮在PictureBox3中加载另一个位图(PictureBox3.Image = bm2),它将不会加载。 / p>

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim clr As Integer
    Dim ymax As Integer
    Dim xmax As Integer
    Dim x As Integer
    Dim y As Integer
    Dim bm As Bitmap = PictureBox1.Image
    xmax = bm.Width - 1
    ymax = bm.Height - 1
    For y = 0 To ymax
        For x = 0 To xmax
            With bm.GetPixel(x, y)
                clr = 0.21 * .R + 0.72 * .G + 0.07 * .B
            End With
            bm.SetPixel(x, y, _
            Color.FromArgb(255, clr, clr, clr))
        Next x
    Next y
    PictureBox3.Image = bm
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Dim clr As Integer
    Dim ymax As Integer
    Dim xmax As Integer
    Dim x As Integer
    Dim y As Integer
    Dim bm2 As Bitmap = PictureBox1.Image
    xmax = bm2.Width - 1
    ymax = bm2.Height - 1
    For y = 0 To ymax
        For x = 0 To xmax
            With bm2.GetPixel(x, y)
                clr = (1 * .R + 1 * .G + 1 * .B) / 3
            End With
            bm2.SetPixel(x, y, _
            Color.FromArgb(255, clr, clr, clr))
        Next x
    Next y
    PictureBox3.Image = bm2
End Sub

结束班

1 个答案:

答案 0 :(得分:0)

Dim bm2 As Bitmap = new Bitmap(PictureBox1.Image)