July 2008 - Posts

Loading PNG (and JPG) image from resource using GDI+

Last night while I was translating some of my old animation program from GDI32 to GDI+, I’ve hit a roadblock where GDI+ cannot load PNG (and JPEG) file stored as resource: 

// This code doesn't work
Gdiplus::Bitmap* m_image = Gdiplus::Bitmap::FromResource(hInst, L"IDB_IMAGE1");

I’m thinking of an alternative using Bitmap::FromStream / FindResource / LoadResource combo, but I have one problem, I’m not familiar with Bitmap::FromStream. So I’ve checked CodeProject for some sample code on how to use Bitmap::FromStream, this I think will be a good start at what I want to do.

While I was searching for sample code, I’ve bumped on an article posted by Joe Woodbury entitled Loading JPG & PNG resources using GDI+ (glad I’ve searched CodeProject before going to MSDN). This article and the demo source code is exactly what I need, so I figure I will write a sample program using his CGdiPlusBitmapResource to test it.

Just to make things quicker and smaller, I’ve used David Nash's Win++ for this sample program:

The class CGdiPlusBitmapResource doesn’t need any documentation., all you have to do is create an instance of this class., and call it’s Load function and you’re technically done:

CGdiPlusBitmapResource* m_image = new CGdiPlusBitmapResource();
m_image->Load(IDB_IMAGE, _T("PNG"), hInst);

 

And draw it using Graphics object:

// Create graphics object from HDC
Gdiplus::Graphics g(hDC);

// Draw the PNG image using graohics object
g.DrawImage(*m_image, 0, 0);

 


That’s about it. Then you can delete the m_image when you’re done using it.
Check attached sample program for a working demo. It contains Win++ for writing C++ Win32 application, and CGdiPlusBitmap.h header file for loading images from resources.

If you want to know more about GDI+, here' a good article: Starting with GDI+

Posted by cvega with 2 comment(s)
Filed under: ,

WTL links

Definition taken from Wikipedia Big Smile

The Windows Template Library (WTL) is a free software, object-oriented C++ template library for Win32 development. WTL was created by Microsoft employee Nenad Stefanovic for internal use and later released as an unsupported add-on to Visual Studio and the Win32 Framework SDK. It was developed primarily as a light-weight alternative to the Microsoft Foundation Classes and builds upon Microsoft's ATL, another lightweight API widely used to create COM and ActiveX libraries.

As the subject says, this post only contains useful links about this wonderful library:

Home of WTL in Sorceforge
WTL download from Microsoft download center
WTL on CodeProject - If you're an MFC programmer, check the series WTL for MFC programmers.
GameDev.NET - Using the Windows Template Library part 1
GameDev.NET - Using the Windows Template Library part 2
WTL Wiki
Chris Sells's WTL Makes UI Programming a Joy, Part 1: The Basics
Chris Sells's WTL Makes UI Programming a Joy Part 2: The Bells and Whistles
vicsoe.dk WTL samples

I've also attached the Clipcode's WTL developer's guide ebook (the original link seems to be down at the moment)

Finally, don't forget to join the WTL User Group

Posted by cvega with no comments
Filed under: ,

I'm back :)

Hi guys,

I can't believe my eyes that It's already been 2 years since my last post here. Wow, time flies really fast! 
My hands up, I'm not going to make any excuses for my long absence, the important thing is that I found my way back to DevPinoy Cool

Been busy working with different technologies for the past 2 years, also experienced some bad turns in career shifts etch..
I thought it might be a good refresher to write something about what I learned in my blog.., but I’m kind-of thinking what exactly to write.

Any suggestions?

Posted by cvega with 7 comment(s)