creating a sprite from a file picture  
Author Message
Cavetroll





PostPosted: Visual C# General, creating a sprite from a file picture Top

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.


Visual C#11  
 
 
Paul Louth





PostPosted: Visual C# General, creating a sprite from a file picture Top

Image image = Image.FromFile(fileName);

 
 
Cavetroll





PostPosted: Visual C# General, creating a sprite from a file picture Top

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

 
 
Evan Mulawski





PostPosted: Visual C# General, creating a sprite from a file picture Top

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.



 
 
Evan Mulawski





PostPosted: Visual C# General, creating a sprite from a file picture Top

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

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

using System;

namespace Project1

{

Image image1;

public Form1()

{

}

public void NewMethod()

{

button1.Image = image1;

}

}