name22

Color Get ARGB Components

Nov 17th, 2012
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GDIPlus.au3>
  2. #include <Color.au3>
  3.  
  4. ; -Author: name22 (www.autoit.de)
  5.  
  6. $iX = 0
  7. $iY = 0
  8.  
  9. $sFile = FileOpenDialog("Bild auswählen", "", "Images (*.jpg;*.bmp;*.png)")
  10. If @error Then Exit
  11.  
  12. _GDIPlus_Startup()
  13.  
  14. $hBitmap = _GDIPlus_ImageLoadFromFile($sFile)
  15. $iColor = 0x01020304; _GDIPlus_GetPixel($hBitmap, $iX, $iY)
  16. $tARGB = DllStructCreate("BYTE[4]")
  17. DllStructSetData($tARGB, 1, $iColor)
  18.  
  19. $iA = DllStructGetData($tARGB, 1, 4)
  20. $iR = DllStructGetData($tARGB, 1, 3)
  21. $iG = DllStructGetData($tARGB, 1, 2)
  22. $iB = DllStructGetData($tARGB, 1, 1)
  23.  
  24. MsgBox(0, "Farbe:", "Alpha: " & @TAB & $iA & @CRLF & "Rot: " & @TAB & $iR & @CRLF & "Grün: " & @TAB & $iG & @CRLF & "Blau: " & @TAB & $iB & @CRLF & @CRLF & "Gesamt: 0x" & Hex($iA, 2) & Hex($iR, 2) & Hex($iG, 2) & Hex($iB, 2))
  25.  
  26. _GDIPlus_ImageDispose($hBitmap)
  27. _GDIPlus_Shutdown()
  28.  
  29. Func _GDIPlus_GetPixel($hBitmap, $x, $y)
  30.     ; Prog@ndy
  31.     Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $x, "int", $y, "dword*", 0)
  32.     If @error Then Return SetError(1, 0, 0)
  33.     Return SetError($result[0], 1, $result[4])
  34. EndFunc   ;==>_GDIPlus_GetPixel
  35.  
  36. Func _GDIPlus_SetPixel($hBitmap, $x, $y, $ARGB)
  37.     ; Prog@ndy
  38.     Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapSetPixel", "ptr", $hBitmap, "int", $x, "int", $y, "dword", $ARGB)
  39.     If @error Then Return SetError(1, 0, 0)
  40.     Return SetError($result[0], 1, $result[0] = 0)
  41. EndFunc   ;==>_GDIPlus_SetPixel
  42.  
  43. Func _ColorGetARGB($iColorARGB)
  44.     ;Author: name22 (www.autoit.de)
  45.     Local $aRet_ARGB[4], $tARGB_Tmp = DllStructCreate("BYTE[4]")
  46.  
  47.     DllStructSetData($tARGB_Tmp, 1, $iColorARGB)
  48.     $aRet_ARGB[0] = DllStructGetData($tARGB_Tmp, 1, 4) ;Alpha
  49.     $aRet_ARGB[1] = DllStructGetData($tARGB_Tmp, 1, 3) ;Red
  50.     $aRet_ARGB[2] = DllStructGetData($tARGB_Tmp, 1, 2) ;Green
  51.     $aRet_ARGB[3] = DllStructGetData($tARGB_Tmp, 1, 1) ;Blue
  52.  
  53.     Return $aRet_ARGB
  54. EndFunc
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×