Thread: photo in program

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    photo in program

    hi

    I was wondering, how do you insert a photo from file in your program?

  2. #2
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    I'd imagine you'd want to use a graphics API like DirectX or OpenGL to handle that.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    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.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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.
    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;
    }
    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 . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM