Jump to content

Recommended Posts

Posted (edited)

Hi everyone,

Help me change "getpx" Func. i want return value is int 256 color (not grey)

(don't change $hBitmap or make clone)

Here code 

#include <GDIPlus.au3>
Global $File = @ScriptDir&"\test.bmp"

_GDIPlus_Startup()
Global $hBitmap = _GDIPlus_BitmapCreateFromFile($File)

ConsoleWrite(getpx(87, 284)&@CRLF)

_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_Shutdown()

;================================================
Func getpx($x, $y)
    Local $iColor, $iR, $iG, $iB, $iGrey

    $iColor = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y) ;get current pixel color
    $iR = BitShift(BitAND($iColor, 0x00FF0000), 16) ;extract red color channel
    $iG = BitShift(BitAND($iColor, 0x0000FF00), 8) ;extract green color channel
    $iB = BitAND($iColor, 0x000000FF) ;extract blue color channel

    $iGrey = Hex(Int(($iR + $iG + $iB) / 3), 2)

    Return Int("0x" & $iGrey & $iGrey & $iGrey)
EndFunc

Thank very much.

Edited by 123disconnect
Posted (edited)

Could it be this that you're looking for?

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>

Example()

Func Example()
    Local $hBitmap, $hClone, $hImage, $iX, $iY

    ; Initialize GDI+ library
    _GDIPlus_Startup()

    ; Capture 32 bit bitmap
    $hBitmap = _ScreenCapture_Capture("")
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    ; Create X bit bitmap clone
    $iX = _GDIPlus_ImageGetWidth($hImage)
    $iY = _GDIPlus_ImageGetHeight($hImage)
    $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF08INDEXED) ;New format 8 bit / 256 colors

    ; Save bitmap to file
    _GDIPlus_ImageSaveToFile($hClone, "test.bmp")

    ; Clean up resources
    _GDIPlus_ImageDispose($hClone)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hBitmap)

    ; Shut down GDI+ library
    _GDIPlus_Shutdown()

    ;ShellExecute(@MyDocumentsDir & "\GDIPlus_Image.jpg")
EndFunc   ;==>Example

In the help file _GDIPlus_BitmapCloneArea:

    $GDIP_PXF01INDEXED = 1 bit per pixel, indexed
    $GDIP_PXF04INDEXED = 4 bits per pixel, indexed
    $GDIP_PXF08INDEXED = 8 bits per pixel, indexed
    $GDIP_PXF16GRAYSCALE = 16 bits per pixel, grayscale
    $GDIP_PXF16RGB555 = 16 bits per pixel; 5 bits for each RGB component
    $GDIP_PXF16RGB565 = 16 bits per pixel; 5 bits for red, 6 bits for green and 5 bits blue
    $GDIP_PXF16ARGB1555 = 16 bits per pixel; 1 bit for alpha and 5 bits for each RGB component
    $GDIP_PXF24RGB = 24 bits per pixel; 8 bits for each RGB component
    $GDIP_PXF32RGB = 32 bits per pixel; 8 bits for each RGB component. No alpha component.
    $GDIP_PXF32ARGB = 32 bits per pixel; 8 bits for each RGB and alpha component
    $GDIP_PXF32PARGB = 32 bits per pixel; 8 bits for each RGB and alpha component, pre-multiplied
    $GDIP_PXF48RGB = 48 bits per pixel; 16 bits for each RGB component
    $GDIP_PXF64ARGB = 64 bits per pixel; 16 bits for each RGB and alpha component
    $GDIP_PXF64PARGB = 64 bits per pixel; 16 bits for each RGB and alpha component, pre-multiplied

I mean i know you only want to change that one pixel, but if im on the right track, then maybe something can come up, if im totaly off, then forget it.

   
   
   
   
   
   
   
   
   
   
   
   
   
Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
  On 6/5/2020 at 3:27 AM, 123disconnect said:

Hi everyone,

Help me change "getpx" Func. i want return value is int 256 color (not grey)

(don't change $hBitmap or make clone)

Here code 

#include <GDIPlus.au3>
Global $File = @ScriptDir&"\test.bmp"

_GDIPlus_Startup()
Global $hBitmap = _GDIPlus_BitmapCreateFromFile($File)

ConsoleWrite(getpx(87, 284)&@CRLF)

_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_Shutdown()

;================================================
Func getpx($x, $y)
    Local $iColor, $iR, $iG, $iB, $iGrey

    $iColor = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y) ;get current pixel color
    $iR = BitShift(BitAND($iColor, 0x00FF0000), 16) ;extract red color channel
    $iG = BitShift(BitAND($iColor, 0x0000FF00), 8) ;extract green color channel
    $iB = BitAND($iColor, 0x000000FF) ;extract blue color channel

    $iGrey = Hex(Int(($iR + $iG + $iB) / 3), 2)

    Return Int("0x" & $iGrey & $iGrey & $iGrey)
EndFunc

Thank very much.

Expand  

What is a "int 256 color"? You mean you want to return only one byte which represents the greyscale color value?

If yes, then Return Int(($iR + $iG + $iB) / 3) should be sufficient.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Hi UEZ 

i want return value this func is 256 color, (not greyscale). How to edit this function

(this func i'm copy and edit from _GDIPlus_BitmapSetPixel example in help file)

Thank you. 

 

Hi careca

make a clone bitmap obj when you want one pixel only.  is it wasting memory ?

Thank you.

 

Posted (edited)

Like this ?

 

#include <GDIPlus.au3>
Global $File = "r:\test.bmp"

_GDIPlus_Startup()
Global $hBitmap = _GDIPlus_BitmapCreateFromFile($File)

$col=getpx(87, 284)

ConsoleWrite( $col &@CRLF)
ConsoleWrite( Hex($col) &@CRLF)

_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_Shutdown()

;================================================
Func getpx($x, $y)
    Local $iColor, $iR, $iG, $iB

    $iColor = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y) ;get current pixel color
    ConsoleWrite ("color= " & Hex($iColor,6) & @CRLF)
    $iR = BitShift(BitAND($iColor, 0x00FF0000), 16) ;extract red color channel
    $iG = BitShift(BitAND($iColor, 0x0000FF00), 8) ;extract green color channel
    $iB = BitAND($iColor, 0x000000FF) ;extract blue color channel

    Return Int("0x" & Hex($ir,2) & Hex($iG,2) & Hex($ib,2))
EndFunc

 

Of course, you could remove the $ir,$ig and $ib and use  Return int("0x" & Hex($iColor,6))

 

;================================================
Func getpx($x, $y)
    Local $iColor

    $iColor = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y) ;get current pixel color
    Return int("0x" & Hex($iColor,6))
EndFunc

 

Edited by Dan_555

Some of my script sourcecode

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...