Cavetroll

I have spent over 4 hours trying to figure out how to create a sprite from a picture. I have a programming background of turing I know a little bit of visual basic. I can't understand how to load a picture. Any help is appreciated.


Re: Visual C# General creating a sprite from a file picture

Paul Louth

Image image = Image.FromFile(fileName);




Re: Visual C# General creating a sprite from a file picture

Cavetroll

Can you elaborate about what ishould put for the second part (Image.FromFile) Also should the file name be just the name of the file or th location




Re: Visual C# General creating a sprite from a file picture

Evan Mulawski

Image image = Image.FromFile(string fileName);

fileName is just the name, not location if you have the picture file added under bin\Debug (in Solution Explorer, Show All Files).

fileName is location if you have the file in another directory.






Re: Visual C# General creating a sprite from a file picture

Evan Mulawski

Also, if you do have the file under bin\Debug, use an escape sequence.

Image image = Image.FromFile(@"\image.png");

TIP: If you are going to use an image over and over, use this:

using System;

namespace Project1

{

Image image1;

public Form1()

{

image1 = Image.FromFile(@"\image.png");

}

public void NewMethod()

{

button1.Image = image1;

}

}