NO

Author Topic: Saving a bitmap from handle  (Read 457 times)

Offline Vortex

  • Member
  • *
  • Posts: 907
    • http://www.vortex.masmcode.com
Saving a bitmap from handle
« on: December 03, 2024, 08:17:07 PM »
Hello,

Here is a function to save a bitmap from handle :

Code: [Select]
include SaveBmpFromHandle.inc

.data

IID_IPicture GUID <7BF80980h,0BF32h,101Ah,<8Bh,0BBh,00h,0AAh,00h,30h,0Ch,0ABh>>

.code

SaveBmpFromHandle PROC hBitmap:QWORD,FileName:QWORD PARMAREA=4*QWORD

LOCAL BmpSize    :QWORD
LOCAL pd         :PICTDESC
LOCAL pPicture   :QWORD
LOCAL pStream    :QWORD
LOCAL hGlobal    :QWORD
LOCAL _FileName  :QWORD

    lea     rax,pd
    mov     PICTDESC.cbSizeofstruct[rax],SIZEOF PICTDESC
    mov     PICTDESC.picType[rax],PICTYPE_BITMAP
    mov     PICTDESC.bmp.hbitmap[rax],rcx
    mov     PICTDESC.bmp.hpal[rax],0
    mov     _FileName,rdx

    invoke  OleCreatePictureIndirect,ADDR pd,\
            ADDR IID_IPicture,0,ADDR pPicture

    test    rax,rax
    jnz     finish

    invoke  CreateStreamOnHGlobal,0,TRUE,ADDR pStream

    test    rax,rax
    jnz     releasePict

    coinvk  pPicture,IPicture,SaveAsFile,pStream,TRUE,ADDR BmpSize

    test    rax,rax
    jnz     releaseStream

    invoke  GetHGlobalFromStream,pStream,ADDR hGlobal

    test    rax,rax
    jnz     releaseStream

    invoke  GlobalLock,hGlobal
 
    invoke  WriteFileToDisc,_FileName,rax,BmpSize

releaseStream:

    coinvk  pStream,IStream,Release

releasePict:

    coinvk  pPicture,IPicture,Release

finish:

    ret
   
SaveBmpFromHandle ENDP

END
Code it... That's all...