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
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)
Jose Roca has some code....
http://www.jose.it-berater.org/smfforum/index.php?topic=2988.0 (http://www.jose.it-berater.org/smfforum/index.php?topic=2988.0)
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
Hi Yves
I hope it help you ;)
http://www.jose.it-berater.org/smfforum/index.php?topic=4654.0
Hi ToutEnMasm,
Here is a GdipSaveImageToStream example for you.
you have to use FindResource, LoadResource, LockResource
i think Gwapo (Chris) has a nice example out there someplace
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.
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
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
a couple links for you to browse, Yves :P
http://masm32.com/board/index.php?topic=967.0 (http://masm32.com/board/index.php?topic=967.0)
http://masm32.com/board/index.php?topic=309.0 (http://masm32.com/board/index.php?topic=309.0)
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 (http://masm32.com/board/index.php?topic=1889.msg19576#msg19576)
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.
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.
Hi ToutEnMasm,
OK, no problem. Glad to know that it works fine for you.