News:

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

Main Menu

Gdi++ png

Started by ragdog, August 04, 2014, 01:30:32 AM

Previous topic - Next topic

ragdog

Hi all

I have found a good example to load a png from resource and load it with gdi++ to the dialog
devpinoy.org/blogs/cvega/archive/2008/10/26/load-png-jpeg-from-resource-using-gdi-masm.aspx

But i wish use it without push a button oder set a timer

why works it only with button or timer must i redraw the window or InvalidateRect the window?

invoke SetTimer,hWnd,0,100,0
.elseif uMsg == WM_TIMER

invoke gdiplusLoadBitmapFromResource, hInstance, 5000, addr pngType, addr pngImage
invoke RedrawCanvas, hWnd
invoke KillTimer,hWnd,0


Greets,


dedndave

i am not sure about that function, but i would guess it returns an HBITMAP handle in EAX
i don't see in your code where you have stored that handle   :P

ragdog

Hey

here is a masm exmaple but it works only by push a button or use a timer
devpinoy.org/blogs/cvega/archive/2008/10/26/load-png-jpeg-from-resource-using-gdi-masm.aspx


.code
include gdiplusLoadBitmapFromResource.inc
start:

invoke GetModuleHandle,NULL
mov hInstance,eax

    invoke InitCommonControls
    ; Initialize GDI+
invoke GdiplusStartup, addr gdiplusToken, addr gdiplusSInput, NULL

invoke DialogBoxParam,hInstance,IDD_DIALOG,NULL,addr DlgProc,NULL
invoke ExitProcess,0

;########################################################################

DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ps:PAINTSTRUCT
.if uMsg==WM_INITDIALOG




invoke SetTimer,hWnd,0,100,0
.elseif uMsg == WM_TIMER

invoke gdiplusLoadBitmapFromResource, hInstance, 5000, addr pngType, addr pngImage
invoke RedrawCanvas, hWnd
invoke KillTimer,hWnd,0
.elseif uMsg==WM_CLOSE
; Shutdown GDI+
invoke GdipDisposeImage, addr pngImage
invoke GdiplusShutdown, gdiplusToken
invoke EndDialog,hWnd,0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp

; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Redraw the canvas
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
RedrawCanvas proc hWnd:HWND
local graphics:HANDLE
local canvasHwnd:HWND
local rect:RECT
local whiteBrush:DWORD

invoke GetDlgItem, hWnd, 9000
mov canvasHwnd, eax
invoke GetWindowRect, canvasHwnd, addr rect
invoke GdipCreateFromHWND, canvasHwnd, addr graphics
invoke GdipCreateSolidFill, 0ffffffffh, addr whiteBrush
invoke GdipFillRectangleI, graphics, whiteBrush, 0, 0, rect.right, rect.bottom
invoke GdipDrawImage, graphics, pngImage, 0, 0
invoke GdipDeleteBrush, whiteBrush
invoke GdipDeleteGraphics, graphics

ret
RedrawCanvas endp


end start


i have change this include "invoke   FindResource, hInst, lpName, RT_RCDATA"


gdiplusLoadBitmapFromResource proc hInst:HMODULE, lpName:LPSTR, lpType:LPSTR, pBitmapFromStream:DWORD

local rcRes:HRSRC
local hResData:HRSRC
local pResData:HANDLE
local sizeOfRes:DWORD
local hbuffer:HANDLE
local pbuffer:DWORD
local pIStream:DWORD
local hIStream:DWORD

; ------------------------------------------------------------------
; STEP 1: Find the resource
; ------------------------------------------------------------------
invoke FindResource, hInst, lpName, RT_RCDATA



But i wish draw this png without use a timer

ragdog

I have my project uploaded

qWord

You have:
1. A function to load an image object
2. A routine that shows how to paint the image
3. A function that destroys the image object

Possible solution:

1. -> WM_CREATE/WM_INITDIALOG
2. -> WM_PAINT
3. -> WM_DESTROY
MREAL macros - when you need floating point arithmetic while assembling!

ragdog

1. -> WM_CREATE/WM_INITDIALOG
2. -> WM_PAINT

Have i try without good result

Use i WmPaint flicker this image


LOCAL ps:PAINTSTRUCT
.if uMsg==WM_INITDIALOG
invoke gdiplusLoadBitmapFromResource, hInstance, 5000, addr pngType, addr pngImage
.elseif uMsg==WM_PAINT
INVOKE  BeginPaint,hWnd,addr ps

invoke RedrawCanvas, hWnd

    INVOKE  EndPaint,hWnd,addr ps
    xor eax,eax
    ret


Must i update or invalidate this window?

qWord

As long as you don't give us more details in which scenario you will use code, the following example (derived from your code) should be a good starting point.

Also see GDI+ Flat API

MREAL macros - when you need floating point arithmetic while assembling!

ragdog

Nice qword

invoke ValidateRect,hWnd,0 and WM_Paint is the Solution

Thank you

ragdog

Hello Again

I have a little question about Gdip and Transparent png .

I use Win7 and all works fine but under xp is the color lost from the png why?

here is my code.


.elseif uMsg==WM_PAINT
invoke CreateLogo,hWnd,40,20
xor eax,eax
ret



CreateLogo proc hWnd:HWND ,dwX:DWORD,dwY:DWORD
local pGraphics:HANDLE
local xSize :DWORD ; Image width
local ySize :DWORD ; Image height
local whiteBrush:DWORD
LOCAL rect:RECT
LOCAL ps:PAINTSTRUCT
invoke BeginPaint,hWnd,addr ps
invoke GdipCreateFromHDC,ps.hdc, addr pGraphics
invoke GdipGetImageWidth, pngImage, addr xSize
invoke GdipGetImageHeight,pngImage, addr ySize
invoke GdipDrawImageRectI,pGraphics, pngImage, dwX, dwY,xSize,ySize
invoke GdipDeleteGraphics, pGraphics
invoke EndPaint,hWnd,addr ps
xor eax,eax
ret
CreateLogo endp


My screenshots
http://image-upload.de/image/GoCtz5/5743f9bfb1.png


greets,

dedndave

here is a thread in the old forum
maybe this post from Edgar can help...

http://www.masmforum.com/board/index.php?topic=10641.msg78083#msg78083

Edgar likes GoAsm, but you can translate   :P

ragdog

Hi Dave

My Example use Edgar´s code

I think this is a gdiplus version problem or not?

dedndave

it might be
see if you have power point viewer installed
and, see if Edgar's manifest helps

ragdog

Hmm install Powerpoint is a bad idea if i share my project.exe
all must have install it on Xp.

I have think Gdi++ is a better and smaller solution as Madwizard´s Pnglib to use a transparent Png image.

Or gives a better way to use it?

Greets,

mabdelouahab

png+ res or file + transparent

dedndave

for simplicity, i would probably load the PNG into a bitmap, and set a color to be used for transparency
then, use TransparentBlt (GDI function) to display the image
(be sure to include msimg32.inc and msimg32.lib)