Reputation: 1
I have a windows form application with a few buttons, and when I click one button i want a bitmap image do be shown at the form screen. So, basically what I did was :
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);
}
}
}
the function is telling me how the size of the image should be, and Ive declaired the bitmap, but how do I acctually load an image from my computer?
Upvotes: 0
Views: 863
Reputation: 543
Use openFileDialog to let user select the image. Example: http://www.dotnetperls.com/openfiledialog
Or you can just load the path of the image to your fileName. Example: If your image is located at: C:\Image\Pic.jpg then add that to variable.
Upvotes: 1