Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching color from images
#3
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+
Code:
Copy      Help
;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+
Code:
Copy      Help
;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+
Code:
Copy      Help
;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
Code:
Copy      Help
function'GDIP.GpBitmap* hBitmap [hPalette]

;Create this bitmap from GDI bitmap.


if(!GdipInit) ret
Delete

_hresult=GDIP.GdipCreateBitmapFromHBITMAP(hBitmap hPalette +&m_i)
ret +m_i


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)