07-04-2012, 04:40 PM
Examples with GDI+.
Does not require external components, just import GDI+.qml from GDI+
Need it to save/load png.
Macro capture image and save in png format, using GDI+
Macro get color from png file, using GDI+
Macro find color or image in png file, using GDI+
Member function GdipBitmap.FromHBITMAP
Does not require external components, just import GDI+.qml from GDI+
Need it to save/load png.
Macro capture image and save in png format, using GDI+
;file
str sFile="$desktop$\qm test png gdip.png"
;________________________
;capture to memory
__GdiHandle hb
CaptureImageOnScreen(0 0 ScreenWidth ScreenHeight "" hb)
;save as png
#compile "__Gdip"
GdipBitmap im
if(!im.FromHBITMAP(hb)) end "error"
if(!im.Save(sFile)) end "error"
;________________________
;show the image
run sFile
;NOTES
;GDI+ may be unavailable on Windows 2000.
;Png file created with GDI+ is 33% bigger than with GflAx.
Macro get color from png file, using GDI+
;file, pixel
str sFile="$desktop$\qm test png gdip.png"
;int x(8) y(100)
int x(xm) y(ym) ;;from mouse
;________________________
;open file
#compile "__Gdip"
GdipBitmap im
if(!im.FromFile(sFile)) end "error"
;get pixel color
int color
GDIP.GdipBitmapGetPixel(+im x y &color)
color=ColorToARGB(color 0) ;;0xAARRGGBB to 0xBBGGRR
out "0x%06X" color
Macro find color or image in png file, using GDI+
;file, pixel
str sFile="$desktop$\qm test png.png"
;int color=0xFFE0C0
int color=pixel(xm ym) ;;color from mouse
;________________________
;open file
#compile "__Gdip"
GdipBitmap im
if(!im.FromFile(sFile)) end "error"
;get bitmap handle
__GdiHandle hb=im.GetHBITMAP
;find color in bitmap (in memory)
RECT r
if scan(F"color:{color}" hb r 0x280)
,out "color 0x%06X found at x=%i y=%i" color r.left r.top
else out "not found"
;to find image: if scan("file.bmp" hb r 0x280)
Member function GdipBitmap.FromHBITMAP