#include <GDIPlus.au3>
#include <String.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $sImageFile = @ScriptDir & '\6x6.png'
Global $aAryImage = _BitmapGetColorToArray($sImageFile, '[0,0][6,6]')
;~ If Not @error Then _ArrayDisplay($aAryImage)
$Form1 = GUICreate("Form1", 600, 600)
For $i = 0 To UBound($aAryImage) - 1;行
For $x=0 To UBound($aAryImage, 2) - 1
$Label1 = GUICtrlCreateLabel($aAryImage[$i][$x], $x * 82, $i* 82, 80, 80)
GUICtrlSetBkColor(-1, '0x' & $aAryImage[$i][$x])
GUICtrlSetColor (-1, 0xffffff )
Next
Next
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
;~ MsgBox(0, '', _bitmapGetColor($FileErrPNG, 1, 1))
Func _BitmapGetColorToArray($__hBitmap, $__coordinate)
Local $__begin_time = TimerInit()
$__coordinate = _StringBetween($__coordinate, '[', ']');坐标组
$__posi = StringSplit($__coordinate[0], ',', 2)
$__size = StringSplit($__coordinate[1], ',', 2)
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($__hBitmap)
If @error Then
_GDIPlus_Shutdown()
Return SetError(1)
EndIf
Local $Scan0, $iIW, $iIH, $aReg
Local $v_BufferA, $sAllPixels, $tBitmapData
;~ $iIW = _GDIPlus_ImageGetWidth($hImage)
;~ $iIH = _GDIPlus_ImageGetHeight($hImage)
$__x = $__posi[0]
$__y = $__posi[1]
$iIW = $__size[0] - $__posi[0]
$iIH = $__size[1] - $__posi[1]
ConsoleWrite(StringFormat('%s ][ x=%s y=%s w=%s h=%s \n', '_bitmapGetColor', $__x, $__y, $iIW, $iIH))
$tBitmapData = _GDIPlus_BitmapLockBits($hImage, $__x, $__y, $iIW, $iIH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
$Scan0 = DllStructGetData($tBitmapData, "Scan0")
$v_BufferA = DllStructCreate("byte[" & $iIH * $iIW * 4 & "]", $Scan0)
$sAllPixels = DllStructGetData($v_BufferA, 1)
$v_BufferA = 0
_GDIPlus_BitmapUnlockBits($hImage, $tBitmapData)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
$sAllPixels = StringTrimLeft($sAllPixels, 2)
$sAllPixels = StringRegExpReplace($sAllPixels, "(.{2})(.{2})(.{2})(.{2})", "${3}${2}${1}")
$aReg = StringRegExp($sAllPixels, '(.{6})', 3)
If @error Then Return SetError(2)
If UBound($aReg) <> $iIH * $iIW Then Return SetError(4)
Local $aRet[$iIH][$iIW], $h = 0, $w = 0
For $i = 0 To UBound($aReg) - 1
$aRet[$h][$w] = $aReg[$i]
$w += 1
If $w > $iIW - 1 Then
$w = 0
$h += 1
EndIf
Next
ReDim $aReg[0]
$aReg = 0
ConsoleWrite(StringFormat('%s ][ %s \n', '_bitmapGetColor', TimerDiff($__begin_time)))
Return $aRet
EndFunc ;==>_BitmapGetColorToArray