hi
I was wondering, how do you insert a photo from file in your program?
Printable View
hi
I was wondering, how do you insert a photo from file in your program?
I'd imagine you'd want to use a graphics API like DirectX or OpenGL to handle that.
Perhaps also GD depending on what you want:
OpenGL - good for showing photos
SDL - Good for showing photos and custom manipulation, could mix with OpenGL: Tutorial
GD - I like using this for picture manipulation but not showing it
DevIL - I used it once, can't say much
Perhaps you mean to package the program with the image not being a seperate file but "embeded" into the code. That I don't know but is doable.
Displaying images is hard. Looking at your recent threads, you probably wouldn't be up to the task at the moment. I mean, you could try it if you wanted, but it would involve a lot of code. Here's a simple SDL program that displays an image.
I just typed that into the quick reply box, so there's no guarantee it will work. But you can see how complicated things can be with images . . . .Code:#include "SDL.h"
int main(int argc, char *argv[]) {
SDL_Surface *image;
SDL_Event event;
int quit = 0;
if(SDL_Init(SDL_INIT_VIDEO) < 0) return 1;
image = SDL_LoadBMP("file.bmp");
if(!image) return 1;
if(!SDL_SetVideoMode(image->w, image->h, 0, SDL_SWSURFACE)) return 1;
while(!quit) {
SDL_BlitSurface(image, 0, SDL_GetVideoSurface(), 0);
while(SDL_WaitEvent(&event)) {
switch(event->type) {
case SDL_QUIT:
case SDL_KEYDOWN:
quit = 1;
}
}
}
SDL_FreeSurface(image);
return 0;
}
thanks for the replies. i didn't know it was that hard.
but i didn't need it that much anyway. I'll just learn more c++ before trying something like this.