News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

gdiplus loading a file from a resource

Started by TouEnMasm, May 11, 2013, 11:35:18 PM

Previous topic - Next topic

TouEnMasm


I try to make this without success.
the file in the resource is in any supported formats.
bmp seem possible.
Others not,any idea ?
I have used GdipLoadImageFromStream then GdipSaveImageToStream.
GdipSaveImageToStream failed.
method:
Quote
   invoke GlobalAlloc,GHND,16  ;
   mov Hnewglob,eax   
   
   invoke CreateStreamOnHGlobal,Hnewglob, TRUE, ADDR newstream
   invoke GetEncoderClsid,PUU(szencode,"image/bmp",0),addr CLSID_encoder
   invoke GdipSaveImageToStream,addr gdipImage,newstream,\
            addr CLSID_encoder,NULL

Fa is a musical note to play with CL

qWord

For bitmaps you can also use: GdipCreateBitmapFromResource(HINSTANCE hInstance, GDIPCONST WCHAR* lpBitmapName/resource ID, GpBitmap** bitmap).
(Remarks that the class Bitmap is derived from Image)
MREAL macros - when you need floating point arithmetic while assembling!


TouEnMasm


When i have no problem,it is from a file (on disk) or from a bitmap in resource.
There is problem when it is from a resource.
I try:
copy resource file in global memory,it's work (globalalloc or CoTaskMemAlloc).
I verify it's in memory and then:

;Hglob pointer or Handle
   invoke CreateStreamOnHGlobal, Hglob, TRUE, ADDR ppvIStream
   mov edx,ppvIStream
   invoke GdipCreateBitmapFromStream, ppvIStream,addr gdipImage


Fa is a musical note to play with CL

ragdog

Hi Yves

I hope it help you ;)

http://www.jose.it-berater.org/smfforum/index.php?topic=4654.0

Vortex

Hi ToutEnMasm,

Here is a GdipSaveImageToStream example for you.

dedndave

you have to use FindResource, LoadResource, LockResource

i think Gwapo (Chris) has a nice example out there someplace

TouEnMasm

After a laborious research,I have mixed informations and get a code who work.
First step is in the resource:
Quote
1200 RCDATA "ShapesR90.jpg"
The RCDATA seems the only one giving a final result.Then in code:

invoke FindResourceW, hModule, 1200, RT_RCDATA
mov hResource, eax
invoke LoadResource,hModule, hResource
invoke LockResource, eax
mov PimageFile, eax
invoke SizeofResource, hModule, hResource
mov file.nFileSizeLow, eax
invoke CoTaskMemAlloc,file.nFileSizeLow
;invoke GlobalAlloc,GHND,file.nFileSizeLow  ;
mov Hglob,eax
mov pmem,eax
;--------- Fill the memory --------------------
.if   step == 1
mov esi,PimageFile
mov edi,eax
mov ecx,file.nFileSizeLow
shr ecx,2 ;divise par 4,ignore reste
rep movsd
mov ecx,file.nFileSizeLow
and ecx,3 ;recupère le reste
.if ecx != 0
rep movsb
.endif
;invoke GlobalUnlock,Hglob ;pas supporté par Istream

;-------------- Hglob image file in memory GlobalAlloc ------
; create a stream for the Ipicture object's creator
mov edx,Hglob
invoke CreateStreamOnHGlobal, Hglob, TRUE, ADDR ppvIStream
mov edx,ppvIStream
invoke GdipCreateBitmapFromStream, ppvIStream,addr gdipImage
invoke GdipCreateHBITMAPFromBitmap,gdipImage,addr Hbmp,-1


The GdipCreateHBITMAPFromBitmap failed if the resource isn't in RCDATA
No differences in memory is visible with the debugger.
Fa is a musical note to play with CL

Vortex

Hi ToutEnMasm,

This one works with bitmap from resource :

    invoke       GetModuleHandle,0
    invoke       LoadBitmap,eax,100
   
    invoke       GdipCreateBitmapFromHBITMAP,eax,0,ADDR BmpImage


Code converted to Masm32

Vortex

Hi ToutEnMasm,

Another example :

100 RCDATA "image.png"

    invoke  FindResource,0,100,RT_RCDATA
    invoke  LoadResource,0,eax
    invoke  LockResource,eax
    mov     pPNG,eax
       
    invoke  CoTaskMemAlloc,PNG_FILE_SIZE
    mov     pGlobal,eax
    invoke  MemCopy,pPNG,eax,PNG_FILE_SIZE

    invoke  CreateStreamOnHGlobal,pGlobal,TRUE,ADDR pPNGstream
   
    invoke  GdipLoadImageFromStream,pPNGstream,ADDR PngImage


TouEnMasm

Thanks at all for help.
I see errors on someone:
Quote
100 RCDATA "image.png"
;--------------------------------------
    invoke  FindResource,0,100,RT_RCDATA ;failed need FindResourceW
Now the more complete sample is here ,gdiplus_dcobject.zip sample
http://masm32.com/board/index.php?topic=1889.msg19576#msg19576
Fa is a musical note to play with CL

Vortex

Hi ToutEnMasm,

invoke  FindResource,0,100,RT_RCDATA

This works for me. My OS is Win XP Sp3.

You need to provide a technical explanation to prove that the above code is wrong.

TouEnMasm

erratum
I have verify,it's work with Ansi and Unicode.
It's a sample on the old forum who put me on the bad way.
Fa is a musical note to play with CL

Vortex

Hi ToutEnMasm,

OK, no problem. Glad to know that it works fine for you.