2013-03-14 36 views
0

我有一個帶有幾個按鈕的窗體應用程序,當我點擊一個按鈕時,我想在窗體屏幕上顯示一個位圖圖像。所以,基本上我所做的是:在c#窗體窗體應用程序中加載位圖圖像

public static Bitmap[] images; 

Bitmap tileSheet = new Bitmap(filename); 
      images = new Bitmap[256]; 


public static void LoadImages(string filename) 
     { 
      Bitmap tileSheet = new Bitmap(filename); 
      images = new Bitmap[256]; 

      for (int y = 0; y < 16; y++) 
      { 
       for (int x = 0; x < 16; x++) 
       { 
        images[y * 16 + x] = new Bitmap(32, 32); 
        Graphics g = Graphics.FromImage(images[y * 16 + x]); 
        g.DrawImage(tileSheet, new Rectangle(0, 0, 32, 32), new Rectangle(x * 32, y * 32, 32, 32), GraphicsUnit.Pixel); 
       } 
      } 

     } 

的功能告訴我該怎麼圖像的大小應該和伊夫declaired位圖,但我怎麼acctually從我的電腦中加載圖像?

回答

1

使用openFileDialog讓用戶選擇圖像。 例如:http://www.dotnetperls.com/openfiledialog

或者您可以將圖像的路徑加載到您的fileName。 示例:如果您的圖像位於:C:\ Image \ Pic.jpg,則將其添加到變量中。

相關問題