Thread: Newbie: Displaying jpeg images in C++

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Newbie: Displaying jpeg images in C++

    How can you display a jpeg image in C++? I am using Windows XP and the IDE is Dev-C++.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Which end of the spectrum of answers are you looking for?

    Easy - I don't care what libraries I need, I'd be happy with just supplying a filename and a place to draw it, and let it do all the hard work.

    Hard - I want to decode all the bits in the file myself, and put each pixel on screen how I want to.

    Can you even do pixel bashing anyway?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    This is a very common question.
    Displaying graphics is platform specific, because there are no standard libraries for this.
    You need to use an API or a wrapper to display JPEG images. (Win32 API is good)
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    26
    I'm interested in the same thing. Can you post some links for both methods?

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The windows board seems a more appropriate place for this question.

    The simplest solution is usually to use gdiplus but some people have difficulty converting the headers for use with dev-cpp, so the next simplest approach would be to use OleLoadPicturePath(or OleLoadPicture), since you've only specified jpeg as an image type.

    As others have pointed out already, you could use other libraries or you could spend a lot of time working out how to do the whole thing for yourself.

    edit: There's a method suggested by anonytmouse in this thread which uses a listview control to display the image.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    How can you display a jpeg image in C++? I am using Windows XP and the IDE is Dev-C++

    I will be placing the jpeg image at a specific location on the screen.

    Text will be displayed simutaneously next to the jpeg image using the string variable with cout >>.

    Can you present the code with Easy and Hard? What is pixel bashing?


    Quote Originally Posted by Salem
    Which end of the spectrum of answers are you looking for?

    Easy - I don't care what libraries I need, I'd be happy with just supplying a filename and a place to draw it, and let it do all the hard work.

    Hard - I want to decode all the bits in the file myself, and put each pixel on screen how I want to.

    Can you even do pixel bashing anyway?

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by C2beginner
    Text will be displayed simutaneously next to the jpeg image using the string variable with cout >>
    There's an example by JaWiB in this thread which demonstrates how for bitmaps (windows native image format): please note that this example, while functional after a fashion, was intended as a curiosity and an amusing one at that.
    What is pixel bashing?
    A rhetorical question, methinks - your response implies you still have a great deal yet to learn before you could competently attempt anything like this.

    I'd suggest switching to gui programming and using the listview example previously described as the most expedient - and realistic - approach to accomplish what you intend.

    See the Windows Programming Links sticky at the top of this board to get started with winapi (win32) programming, if you wish to follow this route.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by C2beginner
    I will be placing the jpeg image at a specific location on the screen.

    Text will be displayed simutaneously next to the jpeg image using the string variable with cout >>.

    Can you present the code with Easy and Hard? What is pixel bashing?
    You are making my head ache, IMAGES ARE FOR GUI AND FOR GUI ONLY. You need to learn WIN32 API as Ken Fitlike already said.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading & Displaying Images
    By devarishi in forum C Programming
    Replies: 9
    Last Post: 12-10-2008, 07:05 PM
  2. Displaying animated images.
    By Queatrix in forum Windows Programming
    Replies: 4
    Last Post: 06-14-2005, 09:53 PM
  3. Displaying images
    By geek@02 in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2005, 02:58 AM
  4. tutorial on displaying images
    By Chobo_C++ in forum C++ Programming
    Replies: 1
    Last Post: 04-04-2004, 04:12 PM
  5. Displaying images
    By yodoblec in forum Game Programming
    Replies: 1
    Last Post: 06-08-2003, 02:39 PM