OK all you bug hunters, here's the early release of the image library. Let it unzip to your MASM32 directory and then you can play with the pieces. It includes a sample application (literally stolen from Icz's tuts) (I think it's #5) and the libs themselves.

First, the function protos:


BitmapFromFile PROTO pszFileName:DWORD
BitmapFromMemory PROTO pHeap:DWORD, dwSize:DWORD
BitmapFromResource PROTO hModule:DWORD, lpName:DWORD


To use the functions of the lib, first reference the lib:



include image.inc
includelib image.lib


***READ THIS NEXT PART***
***READ THIS NEXT PART***
***READ THIS NEXT PART***
***READ THIS NEXT PART***

Define the filepath you wish to load:


szFile BYTE "C:\masm32\ImageLib\homer.jpg", 0


***NOTE IT SAID FILEPATH***
***THAT MEANS WHAT IT SAYS***
*** FILE AND PATH, FILE ALONE WILL FAIL***

(emphasis added out of sheer desperation)

Files may be added in several ways (two of these lines should be commented out) in the WM_CREATE message handler


invoke BitmapFromFile, ADDR szFile
invoke BitmapFromResource, hInstance, 2002
invoke BitmapFromResource, hInstance, 2001


Inside the WM_PAINT message handler, copy the bitmap to the screen.


invoke CreateCompatibleDC, hdc
mov tempDC, eax
invoke SelectObject, tempDC, hBmp
mov htbmp, eax
invoke BitBlt, hdc, 0,0,rect.right,rect.bottom, tempDC, 0, 0, SRCCOPY
invoke SelectObject, tempDC, htbmp
invoke DeleteDC, tempDC


Finally, don't forget a resource file:


2001 BITMAP DISCARDABLE "homer.bmp"
2002 IMAGE DISCARDABLE "homer.gif"


Stir well, then bake at 350? for two hours. Server while still hot.



I hope you find this usefull. Your comments are appreciated.


(the download has been corrected for hutch's comment) (I *hope!*)

(Download also corrected for Worrier King's reported problem concerning buffer size) (see later concerning MultiByteToWideChar)
Posted on 2002-03-15 22:56:41 by Ernie
Ernie,

I unzipped the example and tested the three functions.


.ELSEIF uMsg==WM_CREATE
; invoke BitmapFromFile, ADDR szFile
; invoke BitmapFromResource, hInstance, 2002
invoke BitmapFromResource, hInstance, 2001
mov hBmp, eax
ShowReturn 0, eax

BitmapFromFile failed with return value 0
BitmapFromResource worked fine with jpg, gif and bmp.

Compliments, this is good stuff.

Regards,

hutch@movsd.com
Posted on 2002-03-16 00:13:13 by hutch--
Thought I would try a test piece using a larger JPG image. This is good technology as it allows JPG image size storage in resources that can be large images when loaded as bitmaps.

I used a badly underexposed image of my old car after tweaking it in Picture Publisher and saving it as a jpeg file.

Regards,

hutch@movsd.com
Posted on 2002-03-16 01:35:57 by hutch--
Hutch,

First off, actually downloading my own package and installing it led me to duplication your problem loading the image from a file.

Seems I have the wrong path hard coded in for szFileName. Just adjust that string to your actual path and it will work. (Hey, thats why we call em beta versions). The above download has been corrected.

Thanks for your compliments, that is a badge of honor.
Posted on 2002-03-16 10:25:10 by Ernie
Does the file name in BitmapFromFile need to be Unicode, and a full path?
Posted on 2002-03-16 21:25:45 by The Worrier King
Full path, yes. Unicode, no.

I felt sorry for you ASCII types and did the translation to Unicode inside the lib function. ;-)

Check the sample program and the help doc too.
Posted on 2002-03-17 00:52:21 by Ernie
Does this lib work on all Windows versions ?

Looks nice :alright:
Posted on 2002-03-17 12:28:09 by JimmyClif
I applause !
Very nice and useful !

Thanks Ernie !
Posted on 2002-03-17 16:30:19 by JCP
Thanks Jimmy and Readiosys

These lib functions depend on two API functions, OleLoadPicture and OleLoadPicturePath. These require the following versions:

Windows NT/2000/XP: Requires Windows NT 4.0 or later.

Windows 95/98: Requires Windows 95 or later.



PS: My moving GIF control is humming along. I just completed a procedure that returns any single image (as a bitmap of course) from a multiple image .GIF stream.

Now gotta plan out the next step, probably a custom window control that updates itself witn no other program intervention.
Posted on 2002-03-17 17:00:01 by Ernie
i don't use php so can i get the zip file in another format ?

i don't find image.inc and image.lib in masm package i guess in php file.
Posted on 2002-03-17 23:11:49 by newbies
Just left click on the link. Don't right click/save as, that won't work.
Posted on 2002-03-17 23:16:58 by The Worrier King
i don't know what you mean i got the file but i don't know how to open it. what kind of editor ?
Posted on 2002-03-17 23:42:29 by newbies
The file you have is not the archive. Go back to Ernie's message, and left click on the link there.

You can't save an attached file from this forum by right clicking and selecting "save as", which is what it looks like you did.
Posted on 2002-03-17 23:55:40 by The Worrier King
Actually - (I've been asking that question too once) - the attachment.php is the attachment... Just rename it to whatever.zip and it works...

Regards,
JimmyClif
Posted on 2002-03-18 04:10:18 by JimmyClif
Thanks a bunch Ernie. This'll save a lot of headaches for non-COMmies like me.


(edited cause I've been staring at this monitor for way too long and am no longer able to coherently type)
Posted on 2002-03-19 00:12:00 by Will
thank's Jimmy your method is working is it a kind of tricky of programming ? i guess not :)
Posted on 2002-03-19 05:29:56 by newbies
Is paint.exe supposed to do something?
It opens a blank window, and I don't see a picture. But in the paint.asm file I see it calls your loadpicture routines in the WM_CREATE.
This is on Win XP.
Posted on 2002-03-19 12:12:03 by iblis
It's possible it doesn't work on WinXP. I don't have a copy to check it out on.


Anyone get it to work there?
Posted on 2002-03-19 19:09:40 by Ernie
Woohoo

Just wanted to drop a line saying that after some minor changes (had to change 1 line of code) the image.lib did it's wonder already.. The Filesize got reduced from 3.8MB to an amazing 444KB.. Small is beautiful ;)

I'm never working with bmp's again.. (lol)

PS: It works like a charm on XP.
Posted on 2002-03-19 19:14:01 by JimmyClif
Yes paint.exe is supposed to show Ernie's Avatar..
As he put c:\masm32\image\homer.gif in the paint.asm you have
to either put homer into the above mentionned path or recompile
it with wherever you want the path to be...
Posted on 2002-03-19 19:17:21 by JimmyClif