SFML community forums

Bindings - other languages => DotNet => Topic started by: Lamonte on July 07, 2014, 06:26:43 pm

Title: Question regarding image loading.
Post by: Lamonte on July 07, 2014, 06:26:43 pm
Yesterday I was messing around and tried downloading an image from the internet: http://wfiles.brothersoft.com/c/cat-photograph_195926-1280x720.jpg this image to be exact.  The program crashed repeatedly saying it couldn't load the image, so I thought it was to do w/ my bindings (went sort of nuts w/ recompiling etc... lol) and then I opened the image in paint and resaved it to something else and it loaded properly?

Why exactly was the script crashing?  It was a basic:
Image bg = new Image("bg.jpg");

W/ bare minimum window creation:

RenderWindow window = new RenderWindow(new VideoMode(windowSize.X, windowSize.Y), "Window", Styles.Titlebar | Styles.Close);

window.Closed += (object s, EventArgs e) => {
        RenderWindow w = (RenderWindow) s;
        w.Close();
};

Image bg = new Image("bg.jpg");

while(window.IsOpen) {
        window.DispatchEvents();
        window.Clear(Color.Magenta);
        window.Draw(bg);
        window.Display();
}

Which was weird to me.  Note was using the latest source bindings, compiled w/ VS2012 + the CSFML files from here http://nightlybuilds.ch/project/show/4/CSFML/
Title: Re: Question regarding image loading.
Post by: zsbzsb on July 07, 2014, 08:08:13 pm
Does 'bg.jpg' actually exist in your working directory?
Title: Re: Question regarding image loading.
Post by: Lamonte on July 07, 2014, 08:39:10 pm
Of course it existed lol.  Like I said when I downloaded the file from the internet it crashed the program saying it couldn't load the file.  I opened the image and resaved it using mspaint and it worked perfectly fine.  The question is why does the original internet file crash the app?

More clarification: I downloaded the file from the internet to my computer as bg.jpg, crashed.  Opened the same file in mspaint, resaved it, worked fine.
Title: Re: Question regarding image loading.
Post by: zsbzsb on July 07, 2014, 11:11:16 pm
It works wonders to read the documentation (http://www.sfml-dev.org/documentation/2.1/classsf_1_1Image.php#a9e4f2aa8e36d0cabde5ed5a4ef80290b).

Quote
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.
Title: Re: Question regarding image loading.
Post by: Lamonte on July 08, 2014, 02:01:16 am
It works wonders to read the documentation (http://www.sfml-dev.org/documentation/2.1/classsf_1_1Image.php#a9e4f2aa8e36d0cabde5ed5a4ef80290b).

Quote
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

I should have known that it was a progression jpeg, my mistake.