News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GDI+ Screenshot

Started by Max_Power, January 10, 2007, 05:33:45 AM

Previous topic - Next topic

Max_Power

I am trying to take a screenshot and save it as a jpeg using GDI+. The following code is outputing a jpeg of the correct dimensions, but it is all black. I can't seem to figure out to save my life what I am doing wrong (why it is all black)


;Get GDI+ includes off RadASM website
mov gdiStartup.GdiplusVersion,1
and gdiStartup.DebugEventCallback,0
and gdiStartup.SuppressBackgroundThread,0
and gdiStartup.SuppressExternalCodecs,0
invoke GdiplusStartup,ADDR nGDIToken,ADDR gdiStartup,ADDR gdiStartupO

mov hDesktop,FUNC(GetDesktopWindow)
invoke GdipCreateFromHWND,hDesktop,ADDR hGraphics
invoke GetClientRect,hDesktop,ADDR rctDesktop
invoke GdipCreateBitmapFromGraphics,rctDesktop.right,rctDesktop.bottom,hGraphics,ADDR hBitmap
invoke GdipGetImageEncodersSize,ADDR nEncoders,ADDR nEncSize
mov pEncInfo,alloc(nEncSize)
invoke GdipGetImageEncoders,nEncoders,nEncSize,pEncInfo

;Find the correct encoder
mov ebx,pEncInfo
@@: mov eax,[ebx.ImageCodecInfo.MimeType]
add ebx,sizeof ImageCodecInfo
invoke lstrcmpW,eax,SADD("i",0,"m",0,"a",0,"g",0,"e",0,"/",0,"j",0,"p",0,"e",0,"g",0,0,0)
test eax,eax
jz @F
dec nEncoders
jnz @B
@@: sub ebx,sizeof ImageCodecInfo

invoke GdipSaveImageToFile,hBitmap,SADD("x",0,"a",0,"b",0,"c",0,".",0,"j",0,"p",0,"g",0,0,0),ebx,0

; Clean up
free pEncInfo
invoke GdipDisposeImage,hBitmap
invoke GdiplusShutdown,nGDIToken


Any input would be appreciated.