2013-03-14 37 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,则将其添加到变量中。

相关问题