Hi,
I've written a small function that will allow you to load JPG/PNG images from resource using GDI+:
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):
gdiplusLoadBitmapFromResource proto :HMODULE, :LPSTR, :LPSTR, :DWORD
3. Initialize GDI+ on your program's start
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:
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"
.data
pngImage dd NULL
pngType db "PNG", 0
6. Load the image using gdiplusLoadBitmapFromResource:
invoke gdiplusLoadBitmapFromResource, hInstance, 9000, addr pngType, addr pngImage
7. When you're done using the image, dispose it using GdipDisposeImage function:
invoke GdipDisposeImage, addr pngImage
8. Finally, shutdown GDI+ before you exit your program:
invoke GdiplusShutdown, gdiplusToken
I hope you may find this useful.
See the attached sample program.
Cheers,
-chris
[attachment deleted by admin]
Oh I like that, thanks chris! (http://www.quickersoft.com/wink.gif)
Nice work :U
*Clap Clap Clap* @ chris! Thanks for sharing! :cheekygreen: