News:

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

Main Menu

Re: JpgTool application

Started by six_L, June 02, 2020, 03:13:04 AM

Previous topic - Next topic

hutch--

Thanks timo,

That worked perfectly.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

LoadResImage proc ResID:QWORD

    LOCAL MemStream :QWORD
    LOCAL pBMP      :QWORD
    LOCAL hBMP      :QWORD
    LOCAL pRes      :QWORD
    LOCAL rSiz      :QWORD
    LOCAL rDat      :QWORD
    LOCAL stream    :QWORD

    LOCAL var   :QWORD

    mov MemStream, rvcall(GetProcAddress,rvcall(GetModuleHandle,"shlwapi.dll"),"SHCreateMemStream")

    mov pRes, rvcall(FindResource,0,ResID,RT_RCDATA)        ; find the resource
    mov rSiz, rvcall(SizeofResource,0,pRes)                 ; get its size
    mov rDat, rvcall(LoadResource,0,pRes)                   ; load the resource

    mov stream, rvcall(MemStream,rDat,rSiz)                 ; create the memory stream

    rcall GdipCreateBitmapFromStream,stream,ptr$(pBMP)      ; create a GDI+ bitmap
    rcall GdipCreateHBITMAPFromBitmap,pBMP,ptr$(hBMP),0     ; convert it to a Windows bitmap
    rcall GdipDisposeImage,pBMP                             ; delete the GDI+ bitmap

    mov rax, stream
    mov rax, [rax]
    call QWORD PTR [rax+16]                                 ; release the stream

    ; rcall MessageBox,hWnd,LastError$(),"Title",MB_ICONINFORMATION

    mov rax, hBMP                                           ; return the bitmap handle

    ret

LoadResImage endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Vortex

Hi Hutch,

I didn't use any other library. Also, my resource file defines only a bitmap. I will try to modify my example to simulate your project.

Vortex

Hi Hutch,

Could you try the attached new version? Here are the modifications :

start PROC

    mov     rax,OFFSET StartupInfo
    mov     GdiplusStartupInput.GdiplusVersion[rax],1
    invoke  GdiplusStartup,ADDR token,ADDR StartupInfo,0
.
.


    .ifeq edx,WM_CREATE

        invoke  LoadRsrcImage,1000
     
    .elseifeq edx,WM_PAINT


LoadRsrcImage PROC ResID:QWORD

LOCAL BmpImage  :QWORD

        invoke  GdipCreateBitmapFromResource,hInstance,ResID,\
                ADDR BmpImage

        invoke  GdipCreateHBITMAPFromBitmap,BmpImage,\
                ADDR hBitmap,0

        invoke  GdipDisposeImage,BmpImage

        mov     rax,hBitmap
        ret

LoadRsrcImage ENDP

hutch--

Hi Erol,

Your version worked as before but I have tracked it down using your working example. It seems that the GDI+ function will only work with a BMP file. I changed it to a PNG and it no longer worked.

// 1000 BITMAP logo.bmp

1000 RCDATA "logo.png"

This is unfortunate as the code was clean and simple.

jj2007

GdipCreateBitmapFromStream is much more flexible, as it just needs a pointer. That can come from InputFile or from an RCDATA resource, or even straight from the Internet. GuiImage can use all three modes.

Vortex

Here is a jpg loader from memory based on the cooperation of CreateStreamOnHGlobal and GdipCreateBitmapFromStream :

    invoke  CreateStreamOnHGlobal,hGlobal,\
            TRUE,ADDR pStream
           
    test    rax,rax
    jz      @f

    invoke  GlobalUnlock,hGlobal
    invoke  GlobalFree,hGlobal
    jmp     _exit
@@:
    invoke  GdipCreateBitmapFromStream,pStream,\
            ADDR BitmapImage

    invoke  GdipCreateHBITMAPFromBitmap,BitmapImage,\
            ADDR hBitmap,0

hutch--

Thanks Erol,

this looks good. I am up to my eyeballs in code at the moment but I will test it on different image formats soon as I need to be able to load JPG and PNG files from resources.