The MASM Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 03, 2010, 04:56:13 am

Login with username, password and session length
Search:     Advanced search
116888 Posts in 13958 Topics by 1631 Members
Latest Member: anglear_
* Home Help Search Login Register
+  The MASM Forum
|-+  General Forums
| |-+  The Workshop
| | |-+  Load PNG/JPEG from resource using GDI+
« previous next »
Pages: [1] Print
Author Topic: Load PNG/JPEG from resource using GDI+  (Read 2939 times)
gwapo
Chris Vega
Member
*****
Gender: Male
Posts: 177


Void if seal is broken


Load PNG/JPEG from resource using GDI+
« on: October 25, 2008, 08:37:08 pm »

Hi,

I've written a small function that will allow you to load JPG/PNG images from resource using GDI+:

Code:
    gdiplusLoadBitmapFromResource, hInstance, resourceName, resourceType, outImage

    where:
       hInstance      - the module handle where to load the resource
       resourceName   - the name or the ID of the resource
       resourceType   - string pointer that will indicate the type of the resource., e.g., "PNG",0
       outImage       - address of variable where to put the handle of loaded image

Here's how to use it:

1. Add the function gdiplusLoadBitmapFromResource to your program, or include gdiplusLoadBitmapFromResource.inc.
2. Add the proto (so you can use INVOKE to call gdiplusLoadBitmapFromResource):

Code:
gdiplusLoadBitmapFromResource proto :HMODULE, :LPSTR, :LPSTR, :DWORD

3. Initialize GDI+ on your program's start

Code:
GdiplusStartupInput struc
    GdiplusVersion dd ?
    DebugEventCallback dd ?
    SuppressBackgroundThread BOOL ?
    SuppressExternalCodecs BOOL ?
GdiplusStartupInput ends

.data
gdiplusToken dd ?
gdiplusSInput GdiplusStartupInput <1, NULL, FALSE, FALSE>

.code
invoke GetModuleHandle, 0
mov hInstance, eax

; Initialize GDI+
invoke GdiplusStartup, addr gdiplusToken, addr gdiplusSInput, NULL

4. In your resource script, add your image with specified type, something like:

Code:
9000 PNG "myImage.png"

where 2000 is the ID of the resource, and PNG is the type

5. Add a null-terminated string entry to your data section for the type of resource, e.g., "PNG"

Code:
.data
    pngImage dd NULL
    pngType db "PNG", 0

6. Load the image using gdiplusLoadBitmapFromResource:

Code:
invoke gdiplusLoadBitmapFromResource, hInstance, 9000, addr pngType, addr pngImage

7. When you're done using the image, dispose it using GdipDisposeImage function:

Code:
invoke GdipDisposeImage, addr pngImage

8. Finally, shutdown GDI+ before you exit your program:

Code:
invoke GdiplusShutdown, gdiplusToken

I hope you may find this useful.
See the attached sample program.

Cheers,

-chris

* gdiplres.zip (148.3 KB - downloaded 453 times.)
Logged

Bill Cravener
Member
*****
Gender: Male
Posts: 754



Re: Load PNG/JPEG from resource using GDI+
« Reply #1 on: October 25, 2008, 08:57:05 pm »

Oh I like that, thanks chris!
Logged

My MASM32 Examples.

"Sometimes the littlest things in life are the hardest to take. You can sit on a mountain more comfortably than on a tack". . .Anonymous
Vortex
Raider of the lost code
Member
*****
Gender: Male
Posts: 2960



Re: Load PNG/JPEG from resource using GDI+
« Reply #2 on: October 26, 2008, 01:11:41 pm »

Nice work ThumbsUp
Logged

modchip
New Member
*
Posts: 17



Re: Load PNG/JPEG from resource using GDI+
« Reply #3 on: October 27, 2008, 01:42:27 am »

*Clap Clap Clap* @ chris! Thanks for sharing!  cheekygreen
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!