Loading images that aren't BMP...

This is a discussion on Loading images that aren't BMP... within the Windows Programming forums, part of the Platform Specific Boards category; I'm looking for a way to load other image formats such as PNG, JPEG, DDS, etc, and use them like ...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up Loading images that aren't BMP...

    I'm looking for a way to load other image formats such as PNG, JPEG, DDS, etc, and use them like you can with BMP files (ie use with Win32 functions). For example, how could I load a PNG file into a HBITMAP structure?

    I have looked at libpng.org: top level, but that seems to only do PNG files and I'm not sure if it can turn it into a HBITMAP. Anyone know anything about this?

    Thanks.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Have you looked at GDI+ (GDIPlus)?

    MFC CImage or .NET C# Graphics objects will handle most formats, inc. jpg and pgn (IIRC).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Sorry, I forgot to mention, I'm just using C/C++ Win32, no MFC. I haven't done much in the way of the GDI... so this can do it without too much trouble?

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    GDI won't work without a 3rd party library (need GDI+ or .NET).

    You didn't mention your IDE/complier.

    In MSVC you could write a MFC dll to convert the images and call it from your WIN32 app.

    This dll would be very simple, follow the MFC wiz and create a DLL (static link the MFC libs), then export the following function to get the HBITMAP.

    Code:
    #include <atlimage.h>		// CImage 
    #define DLLExport   __declspec (dllexport) //dllimport in app
    
    //error checking required
    DLLExport HBITMAP ConvertImage(char *szFullpath)
    {
            CString sFullpath(szFullpath);
            CImage Image;
            
            Image.Load(sFullpath);
            return Image.Detach();
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Ah, I see. I'll look into this and give it a go soon. Thanks.

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    You can also use something like cximage, and convert the image in memory to a bmp which you then blit into the HBITMAP.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    You don't need any external library (never on Windows)
    GDI+ manages all imaginable formats.
    JPEG and others are also native with COM or Shell apis.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by Alex31 View Post
    You don't need any external library (never on Windows)
    GDI+ manages all imaginable formats.
    JPEG and others are also native with COM or Shell apis.
    If you bothered to read the thread you would have noticed that I already pointed that out in the second post.

    You may have also noticed that GDI (without the '+') will only handle BMPs (and so WILL require a 3rd party lib).

    Please try to keep up....
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    I recommend using OleLoadPicture on Windows. Here's some sample code that uses it.
    CodeProject: Rendering GIF, JPEG, Icon, or Bitmap Files with OleLoadPicture. Free source code and programming help
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. placing two bmp images side by side
    By nina_code in forum C++ Programming
    Replies: 2
    Last Post: 07-14-2009, 11:10 AM
  2. Loading Images in C
    By bucyyohare in forum C Programming
    Replies: 5
    Last Post: 02-28-2008, 04:52 PM
  3. BMP Loading Structs
    By IdioticCreation in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2007, 12:42 PM
  4. how come... (bmp loading)
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 03-21-2006, 08:00 PM
  5. Loading .jpg images from a file
    By Echidna in forum Windows Programming
    Replies: 4
    Last Post: 04-20-2002, 03:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21