Jump to content

How to read data from bitmap?


Recommended Posts

Hi,

Quick question:

I know of the PixelGetColor() method that can be used to get the color of a pixel on the screen, but does there exist a similar method for reading a pixel off of a saved bitmap (without opening it)?

Thanks,

-numegil

Link to comment
Share on other sites

Hi,

Quick question:

I know of the PixelGetColor() method that can be used to get the color of a pixel on the screen, but does there exist a similar method for reading a pixel off of a saved bitmap (without opening it)?

Thanks,

-numegil

This appears to be a way that works.

The pixel colour is in hexadecimal colour format 0xAARRGGBB (Alpha, Red, Green, Blue). Alpha channel is for transparency. Fully opaque is hex FF.

;
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)
Local $hBitmap

_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@MyDocumentsDir & "\bmbluebut.gif"); Enter path/name of image file here.
MsgBox(0, "", _GDIPlus_BitmapGetPixel($hBitmap, 1, 1)); 0,0 is top left corner pixel of image.

; Clean up resources
_GDIPlus_ImageDispose($hBitmap)

; Shut down GDI+ library
_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"))
EndFunc  ;==>_GDIPlus_BitmapGetPixel
;
Link to comment
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
 Share

  • Recently Browsing   0 members

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