jeantje Posted December 18, 2009 Share Posted December 18, 2009 Hello guys I have a big problem I am creating a ambi-light clone for my computer but i need to set the lights to a color but what color i can't use one pixel as color but i need to make a general RGB value of all pixels of the screen but i really don't know how Please help me Greeting Jean Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 18, 2009 Moderators Share Posted December 18, 2009 jeantje,A quick search (the button is at the top right of the forum ) produced this thread. I know it discusses bitmaps/jpg, but you could always use a ScreenCapture and work on that.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jeantje Posted December 18, 2009 Author Share Posted December 18, 2009 jeantje, A quick search (the button is at the top right of the forum ) produced this thread. I know it discusses bitmaps/jpg, but you could always use a ScreenCapture and work on that. M23 but that is a bit 2 slow in need to get the average color of the full screen with skip of 10 pixels any ideas? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 18, 2009 Moderators Share Posted December 18, 2009 (edited) jeantje,Edit: See post below for a better version. Et voila - it takes about .5 sec per screen on my machine and the result looks pretty accurate: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Color.au3> #include <ScreenCapture.au3> ; Credit: Malkey for the basic GDI code ; Capture screen _GDIPlus_Startup() $hBMP = _ScreenCapture_Capture() $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) $iAverage_Colour = _Screen_Average_Colour($hImage) ConsoleWrite($iAverage_Colour & @CRLF) _GDIPlus_GraphicsDispose($hImage) _GDIPlus_Shutdown() ; ------------- Func _Screen_Average_Colour($hImage2) Local $hBitmap1, $Reslt, $width, $height, $stride, $format, $Scan0, $v_Buffer, $v_Value, $iIW, $iIH Local $iBlue = 0, $iGreen = 0, $iRed = 0 Local $iFractional_Blue = 0, $iFractional_Green = 0, $iFractional_Red = 0 $iIW = _GDIPlus_ImageGetWidth($hImage2) $iIH = _GDIPlus_ImageGetHeight($hImage2) $hBitmap1 = _GDIPlus_BitmapCloneArea($hImage2, 0, 0, $iIW, $iIH, $GDIP_PXF32ARGB) $Reslt = _GDIPlus_BitmapLockBits($hBitmap1, 0, 0, $iIW, $iIH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") ;$format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") For $i = 0 To $iIW - 1 Step 10 For $j = 0 To $iIH - 1 Step 10 $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)) ; Get colour value of pixel $v_Value = DllStructGetData($v_Buffer, 1) ; Count $iBlue += _ColorGetBlue($v_Value) $iGreen += _ColorGetGreen($v_Value) $iRed += _ColorGetRed($v_Value) Next $iFractional_Blue += $iBlue * 10 / $iIH $iBlue = 0 $iFractional_Green += $iGreen * 10 / $iIH $iGreen = 0 $iFractional_Red += $iRed * 10 / $iIH $iRed = 0 Next $avBlue = Hex(Round($iFractional_Blue * 10 / $iIW, 0), 2) $avGreen = Hex(Round($iFractional_Green * 10 / $iIW, 0), 2) $avRed = Hex(Round($iFractional_Red * 10 / $iIW, 0), 2) _GDIPlus_BitmapUnlockBits($hBitmap1, $Reslt) Return ($avRed & $avGreen & $avBlue) EndFunc ;==>_Screen_Average_ColourIf you want it any faster - write your own! M23 Edited December 19, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 19, 2009 Moderators Share Posted December 19, 2009 (edited) jeantje,Here is a more flexible version which allows you to choose the screen area to measure and the sample rate of the pixels: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Color.au3> #include <ScreenCapture.au3> ; Credit: Malkey for the basic GDI code ; Parameters: Pixel_Step, Left, Top, Width, Height - so this will average the top left hand 200x200 square measuring every 10 pixels $iAverage_Colour = _Area_Average_Colour(10, 0, 0, 200, 200) ConsoleWrite($iAverage_Colour & @CRLF) ; ------------- Func _Area_Average_Colour($iStep = 1, $iLeft = 0, $iTop = 0, $iWidth = @DesktopWidth, $iHeight = @DesktopHeight) Local $iBlue = 0, $iGreen = 0, $iRed = 0, $iInterim_Blue = 0, $iInterim_Green = 0, $iInterim_Red = 0, $iInner_Count = 0, $iOuter_Count = 0 _GDIPlus_Startup() Local $hBMP = _ScreenCapture_Capture("", $iLeft, $iTop, $iLeft + $iWidth, $iTop + $iHeight) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Local $hBitmap = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iWidth, $iHeight, $GDIP_PXF32ARGB) Local $tRes = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits() Local $iLock_Width = DllStructGetData($tRes, "width") Local $iLock_Height = DllStructGetData($tRes, "height") Local $iLock_Stride = DllStructGetData($tRes, "stride") Local $iLock_Scan0 = DllStructGetData($tRes, "Scan0") ; Run through the BitMap testing pixels For $i = 0 To $iWidth - 1 Step $iStep For $j = 0 To $iHeight - 1 Step $iStep Local $v_Buffer = DllStructCreate("dword", $iLock_Scan0 + ($j * $iLock_Stride) + ($i * 4)) ; Get colour value of pixel Local $v_Value = DllStructGetData($v_Buffer, 1) ; Add components $iBlue += _ColorGetBlue($v_Value) $iGreen += _ColorGetGreen($v_Value) $iRed += _ColorGetRed($v_Value) ; Adjust counter $iInner_Count += 1 Next ; Determine average value so far - this prevents value becoming too large $iInterim_Blue += $iBlue / $iInner_Count $iBlue = 0 $iInterim_Green += $iGreen / $iInner_Count $iGreen = 0 $iInterim_Red += $iRed / $iInner_Count $iRed = 0 ; Adjust counters $iInner_Count = 0 $iOuter_Count += 1 Next ; Determine final average Local $avBlue = Hex(Round($iInterim_Blue / $iOuter_Count, 0), 2) Local $avGreen = Hex(Round($iInterim_Green / $iOuter_Count, 0), 2) Local $avRed = Hex(Round($iInterim_Red / $iOuter_Count, 0), 2) ; Clear up _GDIPlus_BitmapUnlockBits($hBitmap, $tRes) _GDIPlus_GraphicsDispose($hImage) _GDIPlus_Shutdown() Return ($avRed & $avGreen & $avBlue) EndFunc ;==>_Area_Average_ColourM23Edit: Minor code change - order of parameters and added default values Edited December 19, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jeantje Posted December 20, 2009 Author Share Posted December 20, 2009 jeantje, Here is a more flexible version which allows you to choose the screen area to measure and the sample rate of the pixels: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Color.au3> #include <ScreenCapture.au3> ; Credit: Malkey for the basic GDI code ; Parameters: Pixel_Step, Left, Top, Width, Height - so this will average the top left hand 200x200 square measuring every 10 pixels $iAverage_Colour = _Area_Average_Colour(10, 0, 0, 200, 200) ConsoleWrite($iAverage_Colour & @CRLF) ; ------------- Func _Area_Average_Colour($iStep = 1, $iLeft = 0, $iTop = 0, $iWidth = @DesktopWidth, $iHeight = @DesktopHeight) Local $iBlue = 0, $iGreen = 0, $iRed = 0, $iInterim_Blue = 0, $iInterim_Green = 0, $iInterim_Red = 0, $iInner_Count = 0, $iOuter_Count = 0 _GDIPlus_Startup() Local $hBMP = _ScreenCapture_Capture("", $iLeft, $iTop, $iLeft + $iWidth, $iTop + $iHeight) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Local $hBitmap = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iWidth, $iHeight, $GDIP_PXF32ARGB) Local $tRes = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits() Local $iLock_Width = DllStructGetData($tRes, "width") Local $iLock_Height = DllStructGetData($tRes, "height") Local $iLock_Stride = DllStructGetData($tRes, "stride") Local $iLock_Scan0 = DllStructGetData($tRes, "Scan0") ; Run through the BitMap testing pixels For $i = 0 To $iWidth - 1 Step $iStep For $j = 0 To $iHeight - 1 Step $iStep Local $v_Buffer = DllStructCreate("dword", $iLock_Scan0 + ($j * $iLock_Stride) + ($i * 4)) ; Get colour value of pixel Local $v_Value = DllStructGetData($v_Buffer, 1) ; Add components $iBlue += _ColorGetBlue($v_Value) $iGreen += _ColorGetGreen($v_Value) $iRed += _ColorGetRed($v_Value) ; Adjust counter $iInner_Count += 1 Next ; Determine average value so far - this prevents value becoming too large $iInterim_Blue += $iBlue / $iInner_Count $iBlue = 0 $iInterim_Green += $iGreen / $iInner_Count $iGreen = 0 $iInterim_Red += $iRed / $iInner_Count $iRed = 0 ; Adjust counters $iInner_Count = 0 $iOuter_Count += 1 Next ; Determine final average Local $avBlue = Hex(Round($iInterim_Blue / $iOuter_Count, 0), 2) Local $avGreen = Hex(Round($iInterim_Green / $iOuter_Count, 0), 2) Local $avRed = Hex(Round($iInterim_Red / $iOuter_Count, 0), 2) ; Clear up _GDIPlus_BitmapUnlockBits($hBitmap, $tRes) _GDIPlus_GraphicsDispose($hImage) _GDIPlus_Shutdown() Return ($avRed & $avGreen & $avBlue) EndFunc ;==>_Area_Average_Colour M23 Edit: Minor code change - order of parameters and added default values But it's still to slow and it crashes on my Acer Aspire One maybe the atom cpu fucks it up? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 20, 2009 Moderators Share Posted December 20, 2009 jeanjte, If reading a full screen of pixels for average colour in about .5 sec is too slow for you - read the last line in my post above: If you want it any faster - write your own!This is AutoIt we are talking about remember. You should think yourself lucky that you are coding in something which can even do this using built-in commands! And even luckier that someone else wrote the code for you! Some people! M23 P.S. And I have no idea why it crashes on your machine. I have posted a more developed version in the Examples forum and no-one else has complained yet. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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