Sign in to follow this  

SDL save Surface as PNG/JPG

Recommended Posts

ianmclean0001    100
Hi there just a quick question. I would like to be able to save a sdl surface as a png or a jpg. I am using sdl_image and have check the documentation there seem to be a load function but not a save function. I have used the SDL_SaveBMP function but I plan to have the image uploaded to a web server and read by php. unfortunately php can't read bmps but it can read jpg,png ect. I'm basically using the image to sort data as pixel colors. hope you can help thanks Ian

Share this post

Link to post
Share on other sites
davetyler    168

has a discussion with some solutions that are out there on the web at the moment.

Rather than give my recommendations I suggest you just have a read through those.

EDIT: Reread my post and it sounds like I know an answer and am not giving it to you! That is definitely not the case.

Share this post

Link to post
Share on other sites
zaneski13    104
You could also use DevIL to load / save images. to save you could just do...

ILuint imageID;
ilGenImages(1, &imageID);

ilTexImage(imageWidth, imageHeight, 1, bytesperpixel, IL_RGB, IL_UNSIGNED_BYTE, pixels); //the third agrument is usually always 1 (its depth. Its never 0 and I can't think of a time when its 2)


ilDeleteImages(1, &imageID);

you just have to get the data pixels from somewhere. I think you can do SDL_Surface::pixels but I'm not sure because I haven't used SDL to render stuff, I use opengl now.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this