save an image using SDL_image? - c++

how can i save a SDL_image to an image file ..
i have an image loaded using SDL IMG_Load() method .. i want to now save it in file ??
i dont want to display it on the surface .. just want to load an image manipulate its pixels and save it back ... dont want to load it on front end ??
so how i can save it to the file ?
was written in some forum
'Not much, at least with SDL_image. SDL_image has only functions for
reading images, not for writing images. SDL has SDL_SaveBMP(), but it's hmm
just for BMPs. You will need to use another library for writing JPEGs.'
see here
thnks

SDL_image has an undocumented IMG_SavePNG() and IMG_SavePNG_RW(). The reason they are undocumented appears to be that they're limited to 32-bit RGBA images, but as this is far and away the most common format, it will likely be enough for your purposes.

You could use a third party library such as corona.
corona::Image* image = corona::OpenImage( "c:/filename.ext", corona::PF_R8G8B8A8 );
// do some stuff with the image...
corona::SaveImage( "c:/filename.ext", PF_R8G8B8A8, image );
delete image;

Related

How can i save png images in sdl?

ok so i want to save images in sdl.
i only know how to save stuff in .txt files.
theoreticlly i could take all the bits of the surface and save them in the .txt file and later load all those bits into a surface manually.
but i don't want to do that because a surface in sdl has to go threw some certain processes witch i don't really know what they do.
like every surface has to go through the SDL_DisplayFormat(SDL_Surface *) function.
and if i load functions threw .txt i won't be able to do that.
and there is probablly a simple function to do this so i want to take the easy way.
so where can i get a function that saves a surface to a png file(preferred SDL function)
Use that one to save the Screen as Bitmap.
SDL_SaveBMP(main_global_stuff.sdl.surface, screenshot_filename);
I just looked quickly; with SDL_Image you're able to load png-files. Take a look here for more solutions and librarys.
SDL_Image

How to re-size .bmp file in C\C++?

I am doing a CBIR system as an assignment.There are 100 .bmp files,but they have different size,how to re-size them to a same size?
Thanks.
Have a look at the CImg Library, it's quite easy to use. You can load your bitmap file then use one of the resize function.
Probably a overkill, but you can take a look on ImageMagick.
You should look at G'MIC, a command-line tool to batch image processing operations.
It is even more advanced than ImageMagick's convert tool.
Basically, you can call it like this :
gmic *.bmp -resize 128,128,1,3,3 -outputp resized_
to resize all your bmp images into 128x128 color images, and save them with filenames prefixed by 'resized_'.
G'MIC is available for Linux, Windows and Mac, at : http://gmic.sourceforge.net

How can I draw a png ontop of another png?

How can I "draw"\"merge" a png top of another png (background) using libpng, while keeping the alpha section of the png being drawn on top of the backhround png. There does not seem to be any tutorials or anything mentioned in the documentation about it.
libpng is a library for loading images stored in the PNG file format. It is not a library for blitting images, compositing images, or anything of that nature. libpng's basic job is to take a file or memory image and turn it into an array of color values. What you're talking about is very much out of scope for libpng.
If you want to do this, you will have to do the image composition yourself manually. Or use a library that can do image composition (cairo, etc).

want to load an image, process it and save it back in file?

I am creating a photo editor app in webos using its hybrid app. I am new to c++.
I don't want to display image on the screen using C++, because on the front end I am using javascript as ui.because javascript UI is better thn PDK... But on the backend I have to use c++ just to process it and save image to the file. I can't save it using javascript because webOS doesn't have support for canvas.toDataURL() method.
So I have to pick an image file from a relative path in the local directory, get its rgb values, process on the rgb values and then saving image back to the directory. Saving as new and replacing the previous.
Ok, now I want assistance from u developers. Also if this is all possibe using the SDL library ?? Also can I crop image in c+|+ as well given x,y coordinates of all of its edges to be cropped from?
I don't know the SDL library well (I suppose it can load and save images) but for loading and saving images you can use the OpenIL/DevIL library, it is quite simple and supports many formats. You could also take a look at OpenCV, but that could be a bit heavy-weight for your purpose. To your second question, You can do everything with the image when it's loaded, just program it. With the right libraries and programmer, C++ can do nearly everything. Sorry for this stupid sentence, but you asked if you can do that in C++ and the answer is nearly always Yes.

Advice on cross-platform OpenGL image loader for textures

I need to load PNGs and JPGs to textures. I also need to save textures to PNGs. When an image exceeds GL_MAX_TEXTURE_SIZE I need to split the image into separate textures.
I want to do this with C++.
What could I do?
Thank you.
I need to load PNGs and JPGs to textures
SDL_Image
Qt 4
or use libpng and libjpeg directly (you don't really want to do that, though).
When an image exceeds GL_MAX_TEXTURE_SIZE I need to split the image into separate textures.
You'll have to code it yourself. It isn't difficult.
DevIL can load and save many image formats including PNG and JPEG. It comes with helper functions that upload these images to OpenGL textures (ilutGLBindTexImage, ilutGLLoadImage) and functions to copy only parts of an image to a new image (ilCopyPixels, can be used to split large textures).
For the loading part SOIL looks rather self-contained.