C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-15-2009, 04:35 PM   #1
Not stupid, just stupider
 
yaya's Avatar
 
Join Date: May 2007
Location: Earthland
Posts: 182
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.
yaya is offline   Reply With Quote
Old 11-15-2009, 06:28 PM   #2
train spotter
 
Join Date: Aug 2001
Location: near a computer
Posts: 3,451
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
novacain is offline   Reply With Quote
Old 11-15-2009, 07:57 PM   #3
Not stupid, just stupider
 
yaya's Avatar
 
Join Date: May 2007
Location: Earthland
Posts: 182
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?
yaya is offline   Reply With Quote
Old 11-17-2009, 10:21 PM   #4
train spotter
 
Join Date: Aug 2001
Location: near a computer
Posts: 3,451
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
novacain is offline   Reply With Quote
Old 11-18-2009, 01:33 AM   #5
Not stupid, just stupider
 
yaya's Avatar
 
Join Date: May 2007
Location: Earthland
Posts: 182
Ah, I see. I'll look into this and give it a go soon. Thanks.
yaya is offline   Reply With Quote
Old 11-18-2009, 02:30 PM   #6
Malum in se
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 3,188
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.
abachler is offline   Reply With Quote
Old 11-19-2009, 06:33 AM   #7
Registered User
 
Join Date: Apr 2007
Posts: 136
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.
Alex31 is offline   Reply With Quote
Old 11-19-2009, 07:24 PM   #8
train spotter
 
Join Date: Aug 2001
Location: near a computer
Posts: 3,451
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
novacain is offline   Reply With Quote
Old 11-20-2009, 12:52 AM   #9
Algorithm Dissector
 
iMalc's Avatar
 
Join Date: Dec 2005
Location: New Zealand
Posts: 2,741
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
iMalc is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:30 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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