creating a sprite from a file picture

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.


Answer this question

creating a sprite from a file picture

  • JasonG271009

    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;

    }

    }



  • hijk

    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.



  • Buddy

    Image image = Image.FromFile(fileName);

  • George2

    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

  • creating a sprite from a file picture