Sign in to follow this  
Followers 0
Madza91

Get pixel color from hiden image

3 posts in this topic

#1 ·  Posted (edited)

Hello, I'm not much good in this, but I made some little script for checking Online Gold Price, and reading value number from image. But, I want hide image and get just number, without showing image. How? Thank you. :)

script example:

;----- example 3 PNG work araund by Zedna
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>
Opt("PixelCoordMode", 2)
Global $link = "http://goldprice.org/NewCharts/gold/images/gold_1d_k_EUR.png"
Global $saveto = @TempDir & "\goldprice.png"
Global $hGUI, $hImage, $hGraphic
Global $ImageX = 20, $ImageY = 53
#NoTrayIcon
; Create GUI
$hGUI = GUICreate("Gold Price Live!", 220, 263)
GUICtrlCreateLabel("Gold Price Live!", 0, 0, 220, 30, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Pic1 = GUICtrlCreatePic("", 0, 30, 253, 2, -1, $WS_EX_STATICEDGE)
GUICtrlCreateGroup("", 8, 36, 204, 189)
$Pic1 = GUICtrlCreatePic("", 19, 52, 182, 116, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER))
$label = GUICtrlCreateLabel("Gold Price: " &@CRLF& "Change: ", 20, 174, 180, 48)
$button = GUICtrlCreateButton("Update", 58, 233, 75, 23)
$button1 = GUICtrlCreateButton("Izlaz", 139, 233, 75, 23)
; Load PNG image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($saveto)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()
GUICtrlSetData($label, "Gold Price: " & _CitanjeBrojeva($ImageX+50, $ImageY+4) &@CRLF& "Change: " & _CitanjeBrojeva($ImageX+130, $ImageY+4))
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $button1
Exit
Case $button
_UpdateGoldPrice()
EndSwitch
WEnd
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
; Draw PNG image
Func MY_WM_PAINT($hWnd, $msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, $ImageX, $ImageY)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_PAINT
Func _CitanjeBrojeva($x, $y, $x1 = 80)
Local $text, $broj, $proba, $1
For $a = 0 To $x1
$broj = _GetRow($x+$a, $y)
$proba = _GetRow($x+$a+4, $y)
$proba1 = _GetRow($x+$a-1, $y)
If $proba1 = "00000000" Then
Switch $broj
Case "01111110";0
If $proba = "01111110" Then $text &= 0
Case "01000001";1
If $proba = "00000001" Then $text &= 1
Case "01000011";2
If $proba = "01100001" Then $text &= 2
Case "01000010";3
If $proba = "01101110" Then $text &= 3
Case "00001100";4
If $proba = "11111111" Then $text &= 4
Case "11110010";5
If $proba = "10001110" Then $text &= 5
Case "00111110";6
If $proba = "00001110" Then $text &= 6
Case "10000000";7
If $proba = "11000000" Then $text &= 7
Case "01101110";8
If $proba = "01101110" Then $text &= 8
Case "01110000";9
If $proba = "01111100" Then $text &= 9
Case "00000011";dot
If _GetRow($x+$a+1, $y) = "00000000" Then $text &= "."
Case "00000010";UP
If $proba = "00111110" Then GUICtrlSetColor($label, 0x008000)
Case "00100000";DOWN
If $proba = "00111110" Then GUICtrlSetColor($label, 0xFF0000)
EndSwitch
EndIf
$broj = ""
Next
Return $text
EndFunc
Func _GetRow($x, $y = 0)
Local $1, $2
For $a = 0 To 7
$2 = PixelGetColor($x, $y+$a, $hGUI)
$color1 = Hex($2, 6)
If $color1 = "FFFFFF" Then
$1 &= "0"
Else
$1 &= "1"
EndIf
Next
Return $1
EndFunc
Func _UpdateGoldPrice()
Local $hDownload, $nBytes
GUICtrlSetState($button, $GUI_DISABLE)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
$hDownload = InetGet($link, $saveto, 1, 1)
Do
Sleep(250)
Until InetGetInfo($hDownload, 2) ; Check if the download is complete.
$nBytes = InetGetInfo($hDownload, 0)
InetClose($hDownload) ; Close the handle to release resources.
If $nBytes <> 0 Then
$hImage = _GDIPlus_ImageLoadFromFile($saveto)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, $ImageX, $ImageY)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
GUICtrlSetData($label, "Gold Price: " & _CitanjeBrojeva($ImageX+50, $ImageY+4) &@CRLF& "Change: " & _CitanjeBrojeva($ImageX+130, $ImageY+4) &@CRLF& "Updated: " & @HOUR &":"& @MIN)
Else
MsgBox(0,$nBytes, "Error")
EndIf
GUICtrlSetState($button, $GUI_ENABLE)
EndFunc

EDIT: Or just what function can I use for getting color from custom pixel of some loaded image?

Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites



Bump! :unsure:


[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

You can use the $hImage variable returned from the _GDIPlus_ImageLoadFromFile() function as the $hBitmap parameter in the _GDIPlus_BitmapGetPixel() function in the example.

;This GetPixel method gets the color of a specified pixel in this bitmap.
; Returns hex color format 0xAARRGGBB
Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $tArgb, $pArgb, $aRet
    $tArgb = DllStructCreate("dword Argb")
    $pArgb = DllStructGetPtr($tArgb)
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
    Return Number("0x" & Hex(DllStructGetData($tArgb, "Argb"),8))
EndFunc   ;==>_GDIPlus_BitmapGetPixel

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0