Jump to content

Recommended Posts

Posted

When I searched this forum, I couldn't find any way to get a pixel color from an image.

Done some research and found this on a french AutoIt forum (http://www.autoitscript.fr/forum/viewtopic.php?f=3&t=2993&start=0)

#include <GDIPlus.au3>

$sv_ImageSource = @ScriptDir & "\Source.jpg"
$iPosX = 253
$iPosY = 291

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($sv_ImageSource)

MsgBox(0, "Pixel Color", _GDIPlus_BitmapGetPixel($hImage, $iPosX, $iPosY))

_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

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 "0x" & Hex(DllStructGetData($tArgb, "Argb"), 6)
EndFunc

Hope it will be useful for someone else too!

Posted (edited)

@Vossen

Its possible with _PixelGetColor UDF but the script isn't available anymore...(until Manadar reupload it)

Thank you for your simple and useful UDF !

Cheers, FireFox.

Edited by FireFox
Posted

When I searched this forum, I couldn't find any way to get a pixel color from an image.

Done some research and found this on a french AutoIt forum (http://www.autoitscript.fr/forum/viewtopic.php?f=3&t=2993&start=0)

#include <GDIPlus.au3>

$sv_ImageSource = @ScriptDir & "\Source.jpg"
$iPosX = 253
$iPosY = 291

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($sv_ImageSource)

MsgBox(0, "Pixel Color", _GDIPlus_BitmapGetPixel($hImage, $iPosX, $iPosY))

_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

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 "0x" & Hex(DllStructGetData($tArgb, "Argb"), 6)
EndFunc

Hope it will be useful for someone else too!

Next time, please search these forums using the export function before posting. The export function you should have searched on is "GdipBitmapGetPixel".
Posted (edited)

Next time, please search these forums using the export function before posting. The export function you should have searched on is "GdipBitmapGetPixel".

Sorry, m8, not to be offensive, but do you have to be such an a**?

I may need to search better, but then you'll have to read better!

As I said: "When I searched this forum, I couldn't find any way to get a pixel color from an image" and if I had no idea how to do it, how should I then know I would have to search for GdipBitmapGetPixel?

Atleast I found what I were looking for and I was nice enough to post it here for others usage.

Vossen - Kinda pissed!

Edited by Vossen
Posted

How was he an ass? He was merely pointing out what you should have searched for so you would know next time.

Broken link? PM me and I'll send you the file!

Posted (edited)

This kinda sentence make me kinda pissed: "Next time, please search these forums using the export function before posting."

"Next time," like he just helped me with something really easy, which I just could have searched for in a few seconds,

and the fact that he tells me to search, although I pointed out in the very start of my post that I searched without luck.

Also that he points out what I should have searched for, which is pretty obvious now that I found it.

It might not be what he did, but the way he did it, imo. he should just have left that comment as it was, not there.

Edit: I have to admit, that I may have used a wrong word, when I wrote it I was kinda frustrated and I may have used a wrong choise of words. Sort of regret that, sorry.

Edit: Also as you might see I linked to a French forum, even had to Google Translate it to understand the language just abit, how would I have found that without searching? I searched here for quite a while, I found that GDI+ had to be a way, though eventually I gave up and moved on to Google. After a few hours of searching I found what I needed. Went from scratch to what I needed all by myself, instead of just instant posting here for help and it makes me frustrated that you get the "Next time, please search these forums using the export function before posting." after a few hours of search here and on Google.

Edited by Vossen
  • 10 years later...
Posted
#include <GDIPlus.au3>

$exe = "Cliente       D_24 H_17"
$ss_path = "\\Desktop\c\Users\LEO\Downloads\SS"
$sv_ImageSource = $ss_path&"\"&$exe&".bmp"


$iPosX = 253
$iPosY = 291

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($sv_ImageSource)

MsgBox(0, "Pixel Color", _GDIPlus_BitmapGetPixel($hImage, $iPosX, $iPosY))

_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()


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 "0x" & Hex(DllStructGetData($tArgb, "Argb"), 6)
EndFunc

I know its a old topic, but this script is exactly what i'm need right now.

When i run the script, return this error:

"C:\Users\LEO\Desktop\Novo(a) AutoIt v3 Script - Copia.au3" (25) : ==> Duplicate function name.:
Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)

>Exit code: 1    Time: 0.3236

What could be wrong?

Posted

since the _GDIPlus_BitmapGetPixel() function in new versions of AutoIt has already been included in the <GDIPlus.au3> udf, you have to delete it from your listing, otherwise you have a duplicate function, and all should works as expected.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...