Malkey Posted May 30, 2008 Share Posted May 30, 2008 (edited) This is what it does and how to do it.This script copies the pixels under a resizable, transparent rectangle/square. It can then write those pixels at the mouse position.AlsoCan create a bitmap of desktop, an application window, a sub-window or frame, status bar, tool bars, pop-up window.Pixels Read / WriteOn startup, a small resizeable, transparent square appears at centre of desktop. Drag resize over something small to be pixel copied. The top left corner colour is not copied.Press space bar. Now when Ctrl key is pressed the copied pixels are placed at the cursor position. Press Alt + Left mouse button brings back the transparent rectangle to repeat the process.BitmapsPlace the cursor over the window or bar to be copied and press Shift key.Sometimes the window or bar needs to be clicked on to make it the active object.Also, the resizeable, transparent window can be used to capture that part of the desktop the rectangle is over. Place the cursor over the rectangle and press Shift key. Enjoyexpandcollapse popup#include <WinAPI.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <String.au3> #include <misc.au3> #include <ScreenCapture.au3> ;========== Instructions ==== ; Alt + Left mouse button - Starts transparent resizable rectangle to place over that to be copied. ; Spacebar - Finished with manipulating rectangle to copy pixels below rectangle. ; Ctrl key - Paste captured pixels, minus top left corner color, at mouse position. ; Shift key - Makes Bitmap of the window, sub-window or desktop the mouse is over. If ; the mouse is over the transparent resizable rectangle, the area under ; the rectangle is used to make the bitmap. ; ========> End of Instructions === ; Ref Images from http://www.imagemagick.org/Usage/advanced/ ; Other images @ http://www.cit.gu.edu.au/images/ Const $DIB_RGB_COLORS = 0 Global $GUI, $CopyWin, $PixelArray, $CopyWin, $e, $d, $PixelsReady = 0, $Start = 0 Global Const $WM_LBUTTONDOWN = 0x0201 ; Drag Window 1 of 3 addin Opt("GUIResizeMode", 1) Opt("WinTitleMatchMode", 2) $GUI = GUICreate("Template", 18, 18, -1, -1, BitOR($WS_POPUP, $WS_SIZEBOX, $WS_CLIPCHILDREN), $WS_EX_TOPMOST) WinSetTrans("Template", "", 100) GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove") ; Drag Window 2 of 3 addin While Not _IsPressed("1B") ;Esc to Exit If ((_IsPressed("12") And _IsPressed("01")) Or ($Start = 0)) Then ;Alt + Left Mouse Button - Start rectangle $Start = 1 GUISetState(@SW_SHOW, $GUI) While (Not _IsPressed("20")) ; Spacebar $CopyWin = WinGetPos("Template") If _IsPressed("10") Then Save2BmpShift() ; Shift key Sleep(10) WEnd $CopyWin = WinGetPos("Template") GUISetState(@SW_HIDE, $GUI) GetPixels() EndIf If _IsPressed("11") Then PastePixelPressCtrl() ;Ctrl to paste pixels at mouse position If _IsPressed("10") Then Save2BmpShift() ; Shift key Makes bitmap Sleep(10) WEnd ;Having selected the area of screen to duplicate, this function reads all the pixels within ; the rectangle. It put all the pixel in an array that don't match the color of the top left ; corner pixel. It assigns x, y values to each pixel. These values are relative to the centre ; pixel of the rectangle. Func GetPixels() Local $s, $centX, $centY, $row, $aMPos,$incremArray,$add , $shade = hex(0,2) $PixelsReady = 1 $iWidth = Int($CopyWin[2] / 4) * 4 ; width * height must be divisible by 8 for $tBits structure $iHeight = Int($CopyWin[3] / 2) * 2 ; No remainders wanted $iBitCount = 24 $tBMI = DllStructCreate($tagBITMAPINFO) DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4) DllStructSetData($tBMI, "Width", $iWidth) DllStructSetData($tBMI, "Height", -$iHeight) DllStructSetData($tBMI, "Planes", 1) DllStructSetData($tBMI, "BitCount", $iBitCount) $hDC = _WinAPI_GetDC(0) $hCDC = _WinAPI_CreateCompatibleDC($hDC) ; Siao's bodacious creation $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', _ 'ptr', 0, _ 'ptr', DllStructGetPtr($tBMI), _ 'uint', 1, _ 'ptr*', 0, _ 'ptr', 0, _ 'uint', 0) _WinAPI_DeleteObject(_WinAPI_SelectObject($hCDC, $aDIB[0])) _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDC, $CopyWin[0], $CopyWin[1], $SRCCOPY) $tBits = DllStructCreate('byte[' & $iWidth * $iHeight * $iBitCount / 8 & ']', $aDIB[4]) $sHex = Hex(DllStructGetData($tBits, 1), 6) $row = StringSplit(StringRegExpReplace($sHex, '(.){6}', '$0Chr(0)',0),'Chr(0)',1) $centX = $iWidth / 2 ; Other pixels relative to this x Value $centY = $iHeight / 2 ; Other pixels relative to this y Value $increm = 0 $incremArray = 0 Global $PixelArray[$iWidth * $iHeight+1][3] For $y = 1 To $iHeight For $x = 1 To $iWidth $increm += 1 $add = 0 ; This color @ $row[1], Top Left Corner, excluded from array. if $row[$increm] <> $row[1] Then $incremArray += 1 $PixelArray[$incremArray][0] = ($x - $centX) $PixelArray[$incremArray][1] = ($y - $centY) $PixelArray[$incremArray][2] = "0x" & $row[$increm] EndIf Next Next ReDim $PixelArray[$incremArray+1][3] $PixelArray[0][0] = $incremArray _WinAPI_DeleteObject($aDIB[0]) _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>GetPixels Func PastePixelPressCtrl() Local $aMPos, $aRet If $PixelsReady = 1 Then $aMPos = MouseGetPos() $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $aMPos[0], "uint", $aMPos[1]) $aMPosRel = _WinAPI_GetMousePos(True, $aRet[0]) For $x = 1 To $PixelArray[0][0] SetPixel($aRet[0], $PixelArray[$x][0] + DllStructGetData($aMPosRel, "X"), _ $PixelArray[$x][1] + DllStructGetData($aMPosRel, "Y"), $PixelArray[$x][2]) Next Else MsgBox(0, "Get Pixels First", "First press Alt+Left Mouse button for Rectangle, then spacebar") EndIf EndFunc ;==>PastePixelPressCtrl ;Write pixel to screen Func SetPixel($handle, $x, $y, $color) Local $dc $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle) DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x, "long", $y, "long", $color) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) Return 1 EndFunc ;==>SetPixel Func Save2BmpShift() Local $aMPos, $GuisInfo $aMPos = MouseGetPos() $GuisInfo = _WinInfoFromPoint($aMPos[0], $aMPos[1]) If $GuisInfo[0] = "Template" Then ;$hWnd = ControlGetHandle("Template","", "[CLASS:AutoIt v3 GUI]" ) $apos = WinGetPos("Template") _ScreenCapture_Capture("temp.bmp", $apos[0], $apos[1], $apos[0] + $apos[2], $apos[1] + $apos[3], False) Else _GDIPlus_Startup() If $GuisInfo[1] = $GuisInfo[3] Or $GuisInfo[3] = "Shell_TrayWnd" Then $hWnd = $GuisInfo[2] $apos = WinGetPos("[ACTIVE]") $tPoint = DllStructCreate("int X;int Y") DllStructSetData($tPoint, "X", $apos[0]) DllStructSetData($tPoint, "Y", $apos[1]) DllCall("User32.dll", "int", "ScreenToClient", "hwnd", $hWnd, "ptr", DllStructGetPtr($tPoint)) ;_WinAPI_ScreenToClient($hWnd, $tPoint) $x = DllStructGetData($tPoint, "X") $y = DllStructGetData($tPoint, "Y") $Width = $apos[2] $Height = $apos[3] Else $hWnd = $GuisInfo[2] $pos = ControlGetPos($GuisInfo[4], "", _WinAPI_GetWindowLong($GuisInfo[2], 0xFFFFFFF4)) $x = 0 $y = 0 $Width = $pos[2] $Height = $pos[3] EndIf $hWnd = $GuisInfo[2] $hDC = _WinAPI_GetDC($hWnd) $memDC = _WinAPI_CreateCompatibleDC($hDC) $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height) _WinAPI_SelectObject($memDC, $memBmp) ;~ Func _WinAPI_BitBlt($hDestDC, $iXDest, $iYDest, $iWidth, $iHeight, $hSrcDC, $iXSrc, $iYSrc, $iROP) _WinAPI_BitBlt($memDC, 0, 0, $Width, $Height, $hDC, $x, $y, $SRCCOPY) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($memBmp) _GDIPlus_ImageSaveToFile($hImage, 'temp.bmp') _GDIPlus_ImageDispose($hImage) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject($memBmp) _GDIPlus_Shutdown() EndIf ShellExecute('temp.bmp') EndFunc ;==>Save2BmpShift ;Return : $GuisInfo[0] = Window Text ; $GuisInfo[1] = Class Name ; $GuisInfo[2] = Handle of windowWnd ; $GuisInfo[3] = Owner Class Name ; $GuisInfo[4] = Handle of Owner Window ; A modified Siao Function Func _WinInfoFromPoint($nX, $nY) Local $tStrBuff, $pStrBuff, $aRet, $hWnd, $Info[5] $tStrBuff = DllStructCreate("char[150]") $pStrBuff = DllStructGetPtr($tStrBuff) $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $nX, "uint", $nY) $Info[2] = $aRet[0] ;$hWnd $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $Info[2], "ptr", $pStrBuff, "int", 100) $Info[1] = DllStructGetData($tStrBuff, 1) ; ClassName DllStructSetData($tStrBuff, 1, "") DllCall("user32.dll", "int", "GetWindowText", "hwnd", $Info[2], "ptr", $pStrBuff, "int", 100) $Info[0] = DllStructGetData($tStrBuff, 1) ; Window Text DllStructSetData($tStrBuff, 1, "") $aRet = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $Info[2], "uint", 2) ;$GA_ROOT = 2 $Info[4] = $aRet[0] ; Handle of Owner Window $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $Info[4], "ptr", $pStrBuff, "int", 100) $Info[3] = DllStructGetData($tStrBuff, 1) ;Owner ClassName DllStructSetData($tStrBuff, 1, "") ;ConsoleWrite("text= " &$Info[0] & @CRLF) Return $Info EndFunc ;==>_WinInfoFromPoint ; Drag Window 3 of 3 addin Func _WinMove($hWnd, $Command, $wParam, $lParam) If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0) DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0) Return 1 EndFunc ;==>_WinMoveEdit: Updated script, as per SmOke N's suggestion. The pixels to array has been rewritten. It must be faster and it is definitely a better looking script compared to the original post. Replaced call to func (also removed) with $row = StringSplit(StringRegExpReplace($sHex, '(.){6}', '$0Chr(0)',0),'Chr(0)',1)A word about the inserted image:The bitmap at lower left corner of image was captured from imagemagick.org using this script.The captured pixels from that bitmap and drawn to screen was done with this script.The multiple screen shots of the desktop was done with this script. Edited June 1, 2008 by Malkey Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 30, 2008 Moderators Share Posted May 30, 2008 Really interesting Malkey... I wrote something like:expandcollapse popupFunc GetPixels() Local $s, $Col1_1, $centX, $centY, $row, $aMPos $PixelsReady = 1 $iWidth = Int($CopyWin[2] / 4) * 4 ; width * height must be divisible by 8 for $tBits structure $iHeight = Int($CopyWin[3] / 2) * 2 ; No remainders wanted $iBitCount = 24 $tBMI = DllStructCreate($tagBITMAPINFO) DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4) DllStructSetData($tBMI, "Width", $iWidth) DllStructSetData($tBMI, "Height", -$iHeight) DllStructSetData($tBMI, "Planes", 1) DllStructSetData($tBMI, "BitCount", $iBitCount) $hDC = _WinAPI_GetDC(0) $hCDC = _WinAPI_CreateCompatibleDC($hDC) ; Siao's bodacious creation $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', _ 'ptr', 0, _ 'ptr', DllStructGetPtr($tBMI), _ 'uint', 1, _ 'ptr*', 0, _ 'ptr', 0, _ 'uint', 0) _WinAPI_DeleteObject(_WinAPI_SelectObject($hCDC, $aDIB[0])) _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDC, $CopyWin[0], $CopyWin[1], $SRCCOPY) $tBits = DllStructCreate('byte[' & $iWidth * $iHeight * $iBitCount / 8 & ']', $aDIB[4]) $sHex = Hex(DllStructGetData($tBits, 1), 6) $row = _StringSplitRegExp($sHex, '(.){6}', True) $Col1_1 = $row[1] ; This colour excluded from rectangle later on $centX = $iWidth / 2 ; Other pixels relative to this x Value $centY = $iHeight / 2 ; Other pixels relative to this y Value $increm = 0 $x = 0 For $y = 1 To $iHeight For $x = 1 To $iWidth $increm += 1 If $Col1_1 <> $row[$increm] Then $s &= ($x - $centX) & "," & ($y - $centY) & "," & _ "0x" & StringLeft($row[$increm], 2) & _ StringMid($row[$increm], 3, 2) & StringRight($row[$increm], 2) & " " Next Next $PixDat = StringSplit($s, " ") Global $PixelArray[$PixDat[0] + 1][3] $PixelArray[0][0] = $PixDat[0] For $x = 1 To $PixDat[0] - 1 $row = StringSplit($PixDat[$x], ",") $PixelArray[$x][0] = $row[1] $PixelArray[$x][1] = $row[2] $PixelArray[$x][2] = $row[3] Next _WinAPI_DeleteObject($aDIB[0]) _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>GetPixelsoÝ÷ ض¬·'®ì *.¦W¨~Ë ë-ìÕÊy+kxyûxÓMú®=×Múw+zowÛZ®)à2'xÓMú®=×Múw+zowßn5jjR¶¸§ Þ4Ó~«£uÓ~¢ÊÞÝöã_Ü¡×f w²¢æ«yÚ"aËhrïz»màFFÚáɶÈh®¸+%£§u˦mêì¢gz0¶¢Ø^®Çh¶¬jg)à# èµæºw-í«pY¢{Þ®ÐFFÚ+¾'½êìiÊ'½êí²Ú-ê)¦"µêÞªÝë,jëh×6Func _ColorConvert($nColor);RGB to BGR or BGR to RGB Return _ BitOR(BitShift(BitAND($nColor, 0x000000FF), -16), _ BitAND($nColor, 0x0000FF00), _ BitShift(BitAND($nColor, 0x00FF0000), 16)) EndFuncThat should be a tad faster, it won't be Hexed, but Hex(_ColorConvert($row[$increment]), 6) should be much faster. 2. On your 2 dimensional array method after getting all the values. Wouldn't it be more proficient and less time consuming to just build the 2 dimensional array and add the values within the first loop? I say this because the area you are covering could be vast. Just those two changes should increase the speed of that function considerably. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Toady Posted May 30, 2008 Share Posted May 30, 2008 Wow, good job. Like it a lot. This is a good way to do the Lasso technique to screen selection. www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
Malkey Posted May 30, 2008 Author Share Posted May 30, 2008 Really interesting Malkey... I wrote something like:...... Just those two changes should increase the speed of that function considerably. 1/ If you could post a link to your similar script, I am interested in how you did it. 2/ I was looking at http://www.autoitscript.com/forum/index.ph...st&p=528961 today and thought the same thing about the RGB2GBR conversion. In my script I remember swapping the Left and Right Trim functions when I realized I did not need the conversion. Will be changed simply to & "0x" & $row[$increm] soonish. 3/ Be looking at how the 2d array can be simplified as suggested. May take awhile. Thanks for your comments and Toady, thanks for your reply. Link to comment Share on other sites More sharing options...
Insomniax Posted June 26, 2008 Share Posted June 26, 2008 via the code i can read pixel colors of a region in a screen dc... however i want to read the colors of each pixels FROM a bmp file into an array so that i can compare my bmp's with the ones in screen (my ocr)... So how do i read pixel colors of a bmp image ? I really searched all the forum but could not find anything other than reading bmp file raw data's and etc... Any help would be appreciated thanks. Link to comment Share on other sites More sharing options...
Malkey Posted June 26, 2008 Author Share Posted June 26, 2008 via the code i can read pixel colors of a region in a screen dc... however i want to read the colors of each pixels FROM a bmp file into an array so that i can compare my bmp's with the ones in screen (my ocr)... So how do i read pixel colors of a bmp image ? I really searched all the forum but could not find anything other than reading bmp file raw data's and etc... Any help would be appreciated thanks.This script should help you along. expandcollapse popup#include <WinAPI.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <Constants.au3> ; Modified Siao script ; from http://www.autoitscript.com/forum/index.php?s=&showtopic=71004&view=findpost&p=520497 Const $DIB_RGB_COLORS = 0 _GDIPlus_Startup() ; ===== This ==== ;#cs Local $Path = FileOpenDialog("Choose Image File", "C:\Program Files\Autoio\Examples\" & "", _ "Images (*.gif;*.png;*.jpg;*.bmp)| All (*.*)") If $Path <> "" Then Local $hImg = _GDIPlus_ImageLoadFromFile($Path) If $hImg = 0 Then SetError(1, 0, 0) Local $hBitmap = _GDIPlus_ImageCreateGDICompatibleHBITMAP($hImg) _GDIPlus_ImageDispose($hImg) ;If Not @error Then ExitLoop EndIf ;#ce ;====== OR This ====== ;$Path = "C:\Program Files\Autoio\Examples\grey25X24.gif" ;Local $hImg = _GDIPlus_ImageLoadFromFile ($Path) ;Local $hBitmap = _GDIPlus_ImageCreateGDICompatibleHBITMAP($hImg) ;====== $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) #cs While mod($iWidth*$iHeight,8) <> 0 ; In the $tBits = DllStructCreate statement if mod($iWidth,2) <> 0 then ; there is $iWidth * $iHeight * $iBitCount / 8 $iWidth -= mod($iWidth,2) ; A remainder adds unwanted Zero bits. Else ; If $iBitCount is not divisible by 8, $iHeight -= mod($iHeight,2) ; ,then, this While /Wend loop is required. EndIf Wend #ce $hGui = GUICreate("Bits",$iWidth,$iHeight,-1,-1,$WS_POPUP) GUISetState() $hDC = _WinAPI_GetDC($hGui) $hCDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap ($hCDC, $iWidth,$iHeight) ; $iWidth, $iHeight) _WinAPI_SelectObject ($hCDC, $hBitmap) $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC) _GDIPlus_GraphicsDrawImage ($hGraphic, $hImage, 0, 0) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $iWidth ) DllStructSetData($tSize, "Y", $iHeight) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", 255) DllStructSetData($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow ($hGui, $hDC, 0, $pSize, $hCDC, $pSource, 0, $pBlend, $ULW_ALPHA) $iBitCount = 24 $tBMI = DllStructCreate($tagBITMAPINFO) DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4) DllStructSetData($tBMI, "Width", $iWidth) DllStructSetData($tBMI, "Height", -$iHeight) DllStructSetData($tBMI, "Planes", 1) DllStructSetData($tBMI, "BitCount", $iBitCount) $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'ptr', 0, 'ptr', _ DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0) _WinAPI_DeleteObject(_WinAPI_SelectObject($hCDC, $aDIB[0])) _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDC, 0, 0, $SRCCOPY) $tBits = DllStructCreate('byte[' & $iWidth * $iHeight * $iBitCount / 8 & ']', $aDIB[4]) $sHex = Hex(DllStructGetData($tBits, 1)) GUIDelete($hGui) MsgBox(0, $Path & " Width x Height = " & $iWidth &"X" & $iHeight, $sHex) _GDIPlus_ImageDispose ($hImage) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($aDIB[0]) _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBitmap) _GDIPlus_Shutdown() ; Description:: Converts a GDIPlus-Image to GDI-combatible HBITMAP ; Parameter(s): $hImg -> GDIplus Image object ; Requirement(s): GDIPlus.au3 ; Return Value(s): HBITMAP, compatible with ClipBoard ; Author(s): Prog@ndy Func _GDIPlus_ImageCreateGDICompatibleHBITMAP($hImg) Local $hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) Local $hBitmap = _WinAPI_CopyImage($hBitmap2, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG) _WinAPI_DeleteObject($hBitmap2) Return $hBitmap EndFunc ;==>_GDIPlus_ImageCreateGDICompatibleHBITMAP ; Description:: Copies an image, also makes GDIPlus-HBITMAP to GDI32-BITMAP ; Parameter(s): $hImg -> HBITMAP Object, GDI or GDIPlus ; Requirement(s): WinAPI.au3 ; Return Value(s): Succes: Handle to new Bitmap, Error: 0 ; Author(s): Prog@ndy Func _WinAPI_CopyImage($hImg, $uType = 0, $x = 0, $y = 0, $flags = 0) Local $aResult $aResult = DllCall("User32.dll", "hwnd", "CopyImage", "hwnd", $hImg, "UINT", $uType, _ "int", $x, "int", $y, "UINT", $flags) _WinAPI_Check("_WinAPI_CopyImage", ($aResult[0] = 0), 0, True) Return $aResult[0] EndFunc ;==>_WinAPI_CopyImage The $sHex variable should have the same format as the $sHex variable in the first post. Be aware of the two possible colour formats, BGR an RBG (Red, Blue, Green). There are a lot of other colour formats, but these are the main two for this script. eg in Hex 0xFF0000 in BGR is blue. Hex 0xFF0000 in RGB is red. Should you need conversion between the two, this one-liner seems to works:- $Color = BitAND(BitShift(String(Binary($Color)), 8), 0xFFFFFF) ; Converts RGB to BGR colour and visa-versa Link to comment Share on other sites More sharing options...
Insomniax Posted June 26, 2008 Share Posted June 26, 2008 Wow man! .. Thanks a ton... It works ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now