News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how do i load an Image File that isn't a resource ?

Started by Rainstorm, November 10, 2008, 09:58:48 AM

Previous topic - Next topic

Rainstorm

how do i access an image that isn't a resource ? (like jpg png gif files etc) while the program is running - some programs give you a browse dialog where you can choose an image & after its loaded it can be used by the program in someway. -I did some quick searching in the SDK but the functions seem to refer to loading images in the form of resources which are in an .exe (LoadImage can't do this can it ? - still figuring out all that that function is capable of doing)

= = = = = = = =
Also how  does MAKEINTRESOURCE do what it does ?, just looking to duplicate that in asm.
from the SDK..
QuoteThe MAKEINTRESOURCE macro converts an integer value to a resource type compatible with the resource-management functions. This macro is used in place of a string containing the name of the resource.

many thanks.


MichaelW

For a bitmap file you can use LoadImage, something like this:

invoke LoadImage, NULL, chr$("sample.bmp"),
                 IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE
mov hbmp, eax


I think GDI+ has a function that can handle a variety of image formats, and I think there was a recent thread that discussed this.

I think MAKEINTRESOURCE just basically casts a 16-bit word to a string pointer, to make it acceptable to the compiler as a parameter to the resource-related functions that expect a resource identifier. Because of the format, where the low-order word contains the identifier and the high-order word contains 0, the functions are able to recognize that the identifier is an image ordinal instead of a pointer to an image name. For asm code, you just need to make sure that the identifier is either a pointer to a valid resource name (or filename for LoadImage and LR_LOADFROMFILE) or a value < 65536.

#define MAKEINTRESOURCEA(i) (LPSTR)((ULONG_PTR)((WORD)(i)))
#define MAKEINTRESOURCEW(i) (LPWSTR)((ULONG_PTR)((WORD)(i)))

eschew obfuscation

donkey

You would use GetOpenFileName to get a file name (or supply one hard coded in your program) then use LoadImage with the LR_LOADFROMFILE flag...

invoke LoadImage,NULL,offset FilePath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE or LR_CREATEDIBSECTION

[edit] Cross posted with MichaelW - pretty much the same info here [/edit]

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Rainstorm

Michael, Donkey.. thanks a lot for the explanation & sample code.

what does an OEM image refer to actually ?

gwapo

Quote from: Rainstorm on November 11, 2008, 08:53:08 AM
what does an OEM image refer to actually ?

These are public images defined in your system. In C header, you can find them in penwin.h file.

#define OBM_SKBBTNUP            32767
#define OBM_SKBBTNDOWN          32766
#define OBM_SKBBTNDISABLED      32765

#define OBM_ZENBTNUP            32764
#define OBM_ZENBTNDOWN          32763
#define OBM_ZENBTNDISABLED      32762

#define OBM_HANBTNUP            32761
#define OBM_HANBTNDOWN          32760
#define OBM_HANBTNDISABLED      32759

#define OBM_KKCBTNUP            32758
#define OBM_KKCBTNDOWN          32757
#define OBM_KKCBTNDISABLED      32756

#define OBM_SIPBTNUP            32755
#define OBM_SIPBTNDOWN          32754
#define OBM_SIPBTNDISABLED      32753

#define OBM_PTYBTNUP            32752
#define OBM_PTYBTNDOWN          32751
#define OBM_PTYBTNDISABLED      32750



; load disabled button image from system resource
invoke LoadImage, NULL, OBM_PTYBTNDISABLED, IMAGE_BITMAP, NULL, NULL, LR_DEFAULTSIZE or LR_LOADTRANSPARENT


\

-chris

Farabi

Oh yeah, a few years ago there are some bug at the loadimage function. If you encounter that problem, tell me.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Vortex

Hi Rainstorm,

You can have a look at the showdib example coming with the Masm32 package :

\masm32\examples\exampl02\showdib

It displays a dialog box to select a bitmap image.

Here are two examples. The first one loads and displays a bitmap from memory. The second one, the GDI+ demo loads a bitmap from file and converts it to jpg.

With a little effort, the GDI+ demo can be modified to load png and gif images.

[attachment deleted by admin]

Rainstorm

#7
Vortex, thanks a lot, for the examples - just dloaded them & having a look

chris, got it!! - t y : )

Vortex

Hi Rainstorm,

A note about GDI+ :

QuoteThe graphics file formats supported by GDI+ are BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF.

Not to forget, there are also the image functions from masm32.lib :

BitmapFromFile
BitmapFromResource
BitmapFromMemory

Rainstorm

vortex, thanks for the Alert, & for the function references,.. was really helpfull !  :thumbu