2014-01-12 27 views
0

在Visual Basic .NET Windows窗體應用程序中,我從原始EGA數據創建位圖對象並試圖在PictureBox控件中顯示它們。它可以很好地創建對象,因爲我使用立即窗口調用GetPixel來確定它。 SixteenColorBitmap是我正在使用的庫中的一個類。PictureBox不顯示動態生成的位圖

Function TileImage(Tile As SixteenColorBitmap) As Bitmap 
    Dim b As New Bitmap(32, 32) 
    For y = 1 To 16 
     For x = 1 To 16 
      Dim t = Tile.Color(x - 1, y - 1) 
      Dim c As Color = Drawing.Color.FromArgb(RGB(t.Item1, t.Item2, t.Item3)) 
      b.SetPixel((x - 1) * 2, (y - 1) * 2, c) 
      b.SetPixel((x - 1) * 2 + 1, (y - 1) * 2, c) 
      b.SetPixel((x - 1) * 2, (y - 1) * 2 + 1, c) 
      b.SetPixel((x - 1) * 2 + 1, (y - 1) * 2 + 1, c) 
     Next 
    Next 
    Return b 
End Function 

加載EGA圖形時,對每個圖塊調用這個圖形,並將結果存儲在列表中。當用戶選擇瓷磚,就應該將正確的區塊ID的是,名單,並將其分配給圖片框的Image財產,像這樣:

TileBackground.Image = BackgroundTiles(SelTile(0)) 

TileBackground是一個圖片,BackgroundTiles是名單GDI +位圖和SelTile是選定圖塊的陣列。)當代碼運行時,我確信它正在執行,位圖被分配給屬性,但它不會顯示在表單上,​​即使我調用Invalidate或 。

+0

你試過'BackgroundTiles(SelTile(0)).Save()'而不是爲了調試而從光盤上查看生成的位圖?這可能會清除,如果它真的是picturebox功能失常。 – Jens

回答

0

嗯,我終於搞定了。正如延斯所懷疑的那樣,生成的Bitmap出現了問題,導致PictureBox不知所措(無聲)而不顯示它。下面的代碼,一些未知的原因,工作原理:

Function TileImage(Tile As SixteenColorBitmap) As Bitmap 
    Dim b As New Bitmap(16, 16) 
    For y = 1 To 16 
     For x = 1 To 16 
      Dim t = Tile.Color(x - 1, y - 1) 
      Dim c As Color = Drawing.Color.FromArgb(255, t.Item1, t.Item2, t.Item3) 
      b.SetPixel(x - 1, y - 1, c) 
     Next 
    Next 
    Return b 
End Function 

代替人工手動操作的規模,我有32×32控制顯示我的16x16的圖像。