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
Related
So I have made this program for a game and need help with making it a bit more automatic.
The program takes in an image and then displays it. I'm doing this over textures in OpenGL. When I take the screenshot of the game it is usually something about 700x400. I input the height and width into my program, resize the image to 1024x1024 (making it a POT texture for better compatibility) by adding blank space (the original image stays at the top left corner and goes all the way to (700,400) and the rest is just blank; does anyone know the term for this?) and then load it into my program and adjust the corners so only the part from (0,0) to (700,400) is shown.
That's how I handle the display of the image. Now, I would like to make this automatic. So I'd take a 700x400 picture, pass it to the program which would get the image's width and height (700x400), resize it to 1024x1024 by adding blank space and then load it.
So does anyone know a C++ library capable of doing this? I would still be taking the screenshot manually though.
I am using the Simple OpenGL Image Library (SOIL) for loading the picture (.bmp) and converting it into a texture.
Thanks!
You don't really have to resize by adding blank space to display image properly. In fact, it's really unefficient way to do it, especially because you store images in .bmp format.
SOIL is able to automatically add the blank space when loading textures - maybe just try to load the file as-is, without doing any operations.
From SOIL Documentation:
Can automatically rescale the image to the next largest power-of-two
size
Can load rectangluar textures for GUI elements or splash screens
(requires GL_ARB/EXT/NV_texture_rectangle)
Anyway, you don't have to use texture to display pixels on the screen. I presume you aren't using shaders for rendering - if it all goes through fixed pipeline, there's glDrawPixels function, which will be much simpler. Just remember to change your SOIL call to SOIL_load_image.
I need to apply a texture in a polygon. So I searched and I found many sources but i'm most of them I had problems in include and loading BMP picture. (developing in visual cpp 10). So can anyone tell-me the easy way to load a BMP file and how to apply the texture?
An easy way is to use GDI+ class Bitmap:
http://msdn.microsoft.com/en-us/library/ms534420%28v=vs.85%29.aspx
You create an object with a constructor which takes a filename and then get a pointer to the buffer which contains the pixels using LockBits() method. That method gives you a pointer to a buffer which you can send to OpenGL texture functions.
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.
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;
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.