Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching color from images
#2
Examples with GflAx component.
Image manipulation
Need it to save/load png.

Macro capture image and save in png format
Code:
Copy      Help
;file
str sFile="$desktop$\qm test png.png"

;________________________

;capture to memory
__GdiHandle hb
CaptureImageOnScreen(0 0 ScreenWidth ScreenHeight "" hb)

;save as png
typelib GflAx {059321F1-207A-47A7-93A1-29CDF876FDD3} 1.0
GflAx.GflAx g._create
g.SetPicture(BitmapHandleToIPicture(hb))
g.SaveFormat=GflAx.AX_PNG ;;use other constants to save in other formats
g.SaveBitmap(_s.expandpath(sFile))

;________________________

;show the image
run sFile

Macro get color from png file
Code:
Copy      Help
;file, pixel
str sFile="$desktop$\qm test png.png"
int x(8) y(100)
;int x(xm) y(ym) ;;from mouse

;________________________

;open file
typelib GflAx {059321F1-207A-47A7-93A1-29CDF876FDD3} 1.0
GflAx.GflAx g._create
g.LoadBitmap(_s.expandpath(sFile))

;get pixel color
int color=g.GetColorAt(x y)
out "0x%06X" color

Macro find color or image in png file
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
typelib GflAx {059321F1-207A-47A7-93A1-29CDF876FDD3} 1.0
GflAx.GflAx g._create
g.LoadBitmap(_s.expandpath(sFile))

;get bitmap handle
IPicture p=g.GetPicture
int hb; p.get_Handle(hb)

;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)

Function BitmapHandleToIPicture
Code:
Copy      Help
;/
function'IPicture hBitmap

;Creates IPicture (OLE picture object) from Windows bitmap handle.


IPicture ip
PICTDESC pd.cbSizeofstruct=sizeof(pd)
pd.picType=PICTYPE_BITMAP
pd.bmp.hbitmap=hBitmap

OleCreatePictureIndirect(&pd uuidof(IPicture) 0 &ip)
ret ip


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)