2014-09-26 71 views
0

我正在編寫一個圖片編輯程序,我有一個圖片框,我加載了一個位圖,第一張圖片加載正常,但是如果我想加載第二張圖片, t負載,第一個停留,它不會刷新。我該如何使用2個不同的位圖更改圖片框中的圖像?在Visual Basic中刷新圖片框圖片

我有PictureBox3.Image = bm其中bm是一個位圖變量,它加載正常,但如果我按另一個按鈕加載PictureBox3(PictureBox3.Image = bm2)中的另一個位圖,它將不會加載。

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 

末級

回答

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

添加上你的答案一些意見? – 2014-09-26 02:29:35

+0

非常感謝!問題已解決 – 2014-09-26 03:52:23

+0

此答案是您需要的解決方案嗎? – 2014-09-27 19:47:23