Что нового

Создаём свои "XPI" иконки

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
408
Идею взял с Qt

Загрузка иконки из скрипта:
Код:
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$xpi =  '@ AutoIt' & @CRLF & _
        '{' & @CRLF & _
        '   COLORREF . 0x00000000' & @CRLF & _
        '   COLORREF # 0xFF606060' & @CRLF & _
        '   SIZE     41 5' & @CRLF & _
        '   ROW ".####..##..##.######..####..######.######"' & @CRLF & _
        '   ROW "##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "######.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "##..##..####....##....####..######...##.."' & @CRLF & _
        '}' & @CRLF & _
		'' & @CRLF & _
		'@ MyIcon' & @CRLF & _
        '{' & @CRLF & _
        '   COLORREF . 0x00000000' & @CRLF & _
        '   COLORREF # 0xFFFF0000' & @CRLF & _
        '   COLORREF $ 0xFFB20000' & @CRLF & _
        '   SIZE     20 20' & @CRLF & _
        '   ROW "$$$$................"' & @CRLF & _
        '   ROW "$$$....######......."' & @CRLF & _
        '   ROW "$$...##########....."' & @CRLF & _
        '   ROW "$...####....####...."' & @CRLF & _
        '   ROW "...###........###..."' & @CRLF & _
        '   ROW "..#####........###.."' & @CRLF & _
        '   ROW "..##.###........##.."' & @CRLF & _
        '   ROW ".###..###.......###."' & @CRLF & _
        '   ROW ".##....###.......##."' & @CRLF & _
        '   ROW ".##.....###......##."' & @CRLF & _
        '   ROW ".##......###.....##."' & @CRLF & _
        '   ROW ".##.......###....##."' & @CRLF & _
        '   ROW ".###.......###..###."' & @CRLF & _
        '   ROW "..##........###.##.."' & @CRLF & _
        '   ROW "..###........#####.."' & @CRLF & _
        '   ROW "...###........###..."' & @CRLF & _
        '   ROW "....####....####...$"' & @CRLF & _
        '   ROW ".....##########...$$"' & @CRLF & _
        '   ROW ".......######....$$$"' & @CRLF & _
        '   ROW "................$$$$"' & @CRLF & _
        '}'

$hForm = GUICreate('')
$iPic1 = GUICtrlCreatePic('', 20, 20, 20, 20)
GUICtrlPic_SetXpiImage($iPic1, $xpi, 'MyIcon')
$iPic2 = GUICtrlCreatePic('', 20, 60, 41, 5)
GUICtrlPic_SetXpiImage($iPic2, $xpi, 'AutoIt')
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
Wend

Func GUICtrlPic_SetXpiImage($iCtrl, $sXpi, $sName)

    Local $sBody, $aColor, $aSize, $aImage, $aSet[1][1], $hImage, $hGraphic, $hBmp, $hBitmap, $hPrev

    If (Not IsHWnd($iCtrl)) Then
        $iCtrl = GUICtrlGetHandle($iCtrl)
    EndIf

    $sBody = StringRegExpReplace($sXpi, '(?is).*[email protected]\s+' & $sName & '[^{]+\{([^}]+)\}.*', '$1')
    If ((Not $sBody) Or @error) Then
        Return SetError(1, 0, False)
    EndIf

    $aColor = StringRegExp($sBody, '(?i)COLORREF\s+([^\s]+)\s+(\w+)', 3)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(2, 0, False)
    EndIf

    $aColor = __xpi_to2d($aColor)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(3, 0, False)
    EndIf

    $aSize = StringRegExp($sBody, '(?i)SIZE\s+(\d+)\s+(\d+)', 3)
    If (@error Or (Not IsArray($aSize)) Or (UBound($aSize) <> 2)) Then
        Return SetError(4, 0, False)
    EndIf

    $aImage = StringRegExp($sBody, '(?is)ROW\s+"([^"]*)', 3)
    If (@error Or (Not IsArray($aImage))) Then
        Return SetError(5, 0, False)
    EndIf

    If (UBound($aImage) == $aSize[1]) Then
        ReDim $aSet[$aSize[1]][$aSize[0]]
        For $i = 0 To (UBound($aImage) - 1)
            For $l = 0 To ($aSize[0] - 1)
                If (StringLen($aImage[$i]) <> $aSize[0]) Then
                    Return SetError(6, 0, False)
                EndIf
                $aSet[$i][$l] = StringMid($aImage[$i], ($l + 1), 1)
            Next
        Next
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromScan0($aSize[0], $aSize[1])
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
        $hBmp = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphic)
        For $i = 0 To $aSize[1] - 1
            For $l = 0 To $aSize[0] - 1
                _GDIPlus_BitmapSetPixel($hBmp, $l, $i, __xpi_getcolor($aColor, $aSet[$i][$l]))
            Next
        Next
        _GDIPlus_GraphicsDrawImage($hGraphic, $hBmp, 0, 0)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hPrev = _SendMessage($iCtrl, 0x0172, 0, $hBitmap)
        If $hPrev Then
            _WinAPI_DeleteObject($hPrev)
        EndIf
        $hPrev = _SendMessage($iCtrl, 0x0173)
        If ($hPrev <> $hBitmap) Then
            _WinAPI_DeleteObject($hBitmap)
        EndIf
        _GDIPlus_BitmapDispose($hBmp)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_BitmapDispose($hImage)
        _GDIPlus_Shutdown()
    EndIf

    Return False
EndFunc

Func __xpi_to2d($aColor)

    Local $aTemp[1][2]

    If (IsArray($aColor) And UBound($aColor)) Then
        For $i = 0 To UBound($aColor) - 1 Step 2
            If (($aColor[$i] == '') Or (StringLen($aColor[$i]) > 1)) Then
                Return SetError(1, 0, 0)
            EndIf
            If (($aColor[$i + 1] == '') Or (StringRegExp($aColor[$i + 1], '0x.{8}') <> 1)) Then
                Return SetError(2, 0, 0)
            EndIf
            $aTemp[0][0] += 1
            ReDim $aTemp[$aTemp[0][0] + 1][UBound($aTemp, 2)]
            $aTemp[$aTemp[0][0]][0] = $aColor[$i]
            $aTemp[$aTemp[0][0]][1] = $aColor[$i + 1]
        Next
        Return $aTemp
    EndIf
    Return False
EndFunc

Func __xpi_getcolor($aColor, $sChar)
    If IsArray($aColor) Then
        For $i = 1 To $aColor[0][0]
            If ($sChar == $aColor[$i][0]) Then
                Return $aColor[$i][1]
            EndIf
        Next
    Endif
EndFunc

Загрузка иконки из файла:
Скрипт:
Код:
#include <GDIPlus.au3>

$hFile = FileOpen('image.xpi')
$sRead = FileRead($hFile)
FileClose($hFile)

$hForm = GUICreate('')
$iPic = GUICtrlCreatePic('', 20, 20, 20, 20)
GUICtrlPic_SetXpiImage($iPic, $sRead, 'MyIcon')
GUISetState()

While 1
	Switch GUIGetMsg()
		Case -3
			Exit
	EndSwitch
Wend

Func GUICtrlPic_SetXpiImage($iCtrl, $sXpi, $sName)

    Local $sBody, $aColor, $aSize, $aImage, $aSet[1][1], $hImage, $hGraphic, $hBmp, $hBitmap, $hPrev

    If (Not IsHWnd($iCtrl)) Then
        $iCtrl = GUICtrlGetHandle($iCtrl)
    EndIf

    $sBody = StringRegExpReplace($sXpi, '(?is).*[email protected]\s+' & $sName & '[^{]+\{([^}]+)\}.*', '$1')
    If ((Not $sBody) Or @error) Then
        Return SetError(1, 0, False)
    EndIf

    $aColor = StringRegExp($sBody, '(?i)COLORREF\s+([^\s]+)\s+(\w+)', 3)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(2, 0, False)
    EndIf

    $aColor = __xpi_to2d($aColor)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(3, 0, False)
    EndIf

    $aSize = StringRegExp($sBody, '(?i)SIZE\s+(\d+)\s+(\d+)', 3)
    If (@error Or (Not IsArray($aSize)) Or (UBound($aSize) <> 2)) Then
        Return SetError(4, 0, False)
    EndIf

    $aImage = StringRegExp($sBody, '(?is)ROW\s+"([^"]*)', 3)
    If (@error Or (Not IsArray($aImage))) Then
        Return SetError(5, 0, False)
    EndIf

    If (UBound($aImage) == $aSize[1]) Then
        ReDim $aSet[$aSize[1]][$aSize[0]]
        For $i = 0 To (UBound($aImage) - 1)
            For $l = 0 To ($aSize[0] - 1)
                If (StringLen($aImage[$i]) <> $aSize[0]) Then
                    Return SetError(6, 0, False)
                EndIf
                $aSet[$i][$l] = StringMid($aImage[$i], ($l + 1), 1)
            Next
        Next
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromScan0($aSize[0], $aSize[1])
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
        $hBmp = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphic)
        For $i = 0 To $aSize[1] - 1
            For $l = 0 To $aSize[0] - 1
                _GDIPlus_BitmapSetPixel($hBmp, $l, $i, __xpi_getcolor($aColor, $aSet[$i][$l]))
            Next
        Next
        _GDIPlus_GraphicsDrawImage($hGraphic, $hBmp, 0, 0)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hPrev = _SendMessage($iCtrl, 0x0172, 0, $hBitmap)
        If $hPrev Then
            _WinAPI_DeleteObject($hPrev)
        EndIf
        $hPrev = _SendMessage($iCtrl, 0x0173)
        If ($hPrev <> $hBitmap) Then
            _WinAPI_DeleteObject($hBitmap)
        EndIf
        _GDIPlus_BitmapDispose($hBmp)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_BitmapDispose($hImage)
        _GDIPlus_Shutdown()
    EndIf

    Return False
EndFunc

Func __xpi_to2d($aColor)

	Local $aTemp[1][2]

	If (IsArray($aColor) And UBound($aColor)) Then
		For $i = 0 To UBound($aColor) - 1 Step 2
			If (($aColor[$i] == '') Or (StringLen($aColor[$i]) > 1)) Then
				Return SetError(1, 0, 0)
			EndIf
			If (($aColor[$i + 1] == '') Or (StringRegExp($aColor[$i + 1], '0x.{8}') <> 1)) Then
				Return SetError(2, 0, 0)
			EndIf
			$aTemp[0][0] += 1
			ReDim $aTemp[$aTemp[0][0] + 1][UBound($aTemp, 2)]
			$aTemp[$aTemp[0][0]][0] = $aColor[$i]
			$aTemp[$aTemp[0][0]][1] = $aColor[$i + 1]
		Next
		Return $aTemp
	EndIf
	Return False
EndFunc

Func __xpi_getcolor($aColor, $sChar)
	If IsArray($aColor) Then
		For $i = 1 To $aColor[0][0]
			If $sChar == $aColor[$i][0] Then
				Return $aColor[$i][1]
			EndIf
		Next
	Endif
EndFunc


Файл image.xpi
Код:
@ MyIcon
{
	COLORREF . 0x00000000
	COLORREF # 0xFFFF0000
	COLORREF $ 0xFFB20000
	SIZE     20 20

	ROW	"$$$$................"
	ROW	"$$$....######......."
	ROW	"$$...##########....."
	ROW	"$...####....####...."
	ROW	"...###........###..."
	ROW	"..#####........###.."
	ROW	"..##.###........##.."
	ROW	".###..###.......###."
	ROW	".##....###.......##."
	ROW	".##.....###......##."
	ROW	".##......###.....##."
	ROW	".##.......###....##."
	ROW	".###.......###..###."
	ROW	"..##........###.##.."
	ROW	"..###........#####.."
	ROW	"...###........###..."
	ROW	"....####....####...$"
	ROW	".....##########...$$"
	ROW	".......######....$$$"
	ROW	"................$$$$"
}

Скриншот:


С регулярными выражениями у меня беда, так что, если подкините нормальные паттерны, переделаю.
 
Автор
Viktor1703

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
408
damien2008

Спасибо, забыл предупредить, у меня AutoIt v3.3.10.2 в нём не требуется GDIP, в версиях 3.3.8.1 и ниже нужна GDIP UDF
 

MnM

Post-Hardcore
Сообщения
679
Репутация
90
Хотел добавить в иконку еще 2 пикселя в зеленом цвете:
Код:
'   COLORREF ^ 0x0C431B00' & @CRLF & _

Скрипт не создает иконку

Хотел увеличить размер:
Скрипт не создает иконку :stars:
 
Автор
Viktor1703

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
408
Re: Создаём свои \"XPI\" иконки

MnM
MnM сказал(а):
Хотел увеличить размер:
Скрипт не создает иконку
Оно понятно, я перепутал размерность массива..

Код:
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$xpi =	'@ AutoIt' & @CRLF & _
		'{' & @CRLF & _
		'	COLORREF . 0x00000000' & @CRLF & _
		'	COLORREF # 0xFF606060' & @CRLF & _
		'	SIZE     41 5' & @CRLF & _
		'	ROW	".####..##..##.######..####..######.######"' & @CRLF & _
		'	ROW	"##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
		'	ROW	"######.##..##...##...##..##...##.....##.."' & @CRLF & _
		'	ROW	"##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
		'	ROW	"##..##..####....##....####..######...##.."' & @CRLF & _
		'}'

$hForm = GUICreate('')
$iPic = GUICtrlCreatePic('', 20, 20, 41, 5)
GUICtrlPic_SetXpiImage($iPic, $xpi, 'AutoIt')
GUISetState()

While 1
	Switch GUIGetMsg()
		Case -3
			Exit
	EndSwitch
Wend

Func GUICtrlPic_SetXpiImage($iCtrl, $sXpi, $sName)

	Local $sBody, $aColor, $aSize, $aImage, $aSet[1][1], $hImage, $hGraphic, $hBmp, $hBitmap, $hPrev

	If (Not IsHWnd($iCtrl)) Then
		$iCtrl = GUICtrlGetHandle($iCtrl)
	EndIf

	$sBody = StringRegExpReplace($sXpi, '(?is)@\s+' & $sName & '[\s+|\n|\r]+{[\s+|\n|\r]+(.*?)[\s+|\n|\r]+}', '$1')
	If ((Not $sBody) Or @error) Then
		Return SetError(1, 0, False)
	EndIf

	$aColor = StringRegExp($sBody, '(?i)COLORREF\s+(.*?)\s+(.*?)[\s+|\n|\r]+', 3)
	If (@error Or (Not IsArray($aColor))) Then
		Return SetError(2, 0, False)
	EndIf

	$aColor = __xpi_to2d($aColor)
	If (@error Or (Not IsArray($aColor))) Then
		Return SetError(3, 0, False)
	EndIf

	$aSize = StringRegExp($sBody, '(?i)SIZE\s+(\d+?)\s+(\d+?)[\s+|\n|\r]+', 3)
	If (@error Or (Not IsArray($aSize)) Or (UBound($aSize) <> 2)) Then
		Return SetError(4, 0, False)
	EndIf

	$aImage = StringRegExp($sBody, '(?is)ROW\s+"(.*?)"', 3)
	If (@error Or (Not IsArray($aImage))) Then
		Return SetError(5, 0, False)
	EndIf

	If (UBound($aImage) == $aSize[1]) Then
		ReDim $aSet[$aSize[1]][$aSize[0]]
		For $i = 0 To (UBound($aImage) - 1)
			For $l = 0 To ($aSize[0] - 1)
				If (StringLen($aImage[$i]) <> $aSize[0]) Then
					Return SetError(6, 0, False)
				EndIf
			    $aSet[$i][$l] = StringMid($aImage[$i], ($l + 1), 1)
			Next
		Next
		_GDIPlus_Startup()
		$hImage = _GDIPlus_BitmapCreateFromScan0($aSize[0], $aSize[1])
		$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
		_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
		$hBmp = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphic)
		For $i = 0 To $aSize[1] - 1
			For $l = 0 To $aSize[0] - 1
				_GDIPlus_BitmapSetPixel($hBmp, $l, $i, __xpi_getcolor($aColor, $aSet[$i][$l]))
			Next
		Next
		_GDIPlus_GraphicsDrawImage($hGraphic, $hBmp, 0, 0)
		$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
		$hPrev = _SendMessage($iCtrl, 0x0172, 0, $hBitmap)
		If $hPrev Then
			_WinAPI_DeleteObject($hPrev)
		EndIf
		$hPrev = _SendMessage($iCtrl, 0x0173)
		If ($hPrev <> $hBitmap) Then
			_WinAPI_DeleteObject($hBitmap)
		EndIf
		_GDIPlus_BitmapDispose($hBmp)
		_GDIPlus_GraphicsDispose($hGraphic)
		_GDIPlus_BitmapDispose($hImage)
		_GDIPlus_Shutdown()
	EndIf

	Return False
EndFunc

Func __xpi_to2d($aColor)

	Local $aTemp[1][2]

	If (IsArray($aColor) And UBound($aColor)) Then
		For $i = 0 To UBound($aColor) - 1 Step 2
			If (($aColor[$i] == '') Or (StringLen($aColor[$i]) > 1)) Then
				Return SetError(1, 0, 0)
			EndIf
			If (($aColor[$i + 1] == '') Or (StringRegExp($aColor[$i + 1], '0x.{8}') <> 1)) Then
				Return SetError(2, 0, 0)
			EndIf
			$aTemp[0][0] += 1
			ReDim $aTemp[$aTemp[0][0] + 1][UBound($aTemp, 2)]
			$aTemp[$aTemp[0][0]][0] = $aColor[$i]
			$aTemp[$aTemp[0][0]][1] = $aColor[$i + 1]
		Next
		Return $aTemp
	EndIf
	Return False
EndFunc

Func __xpi_getcolor($aColor, $sChar)
	If IsArray($aColor) Then
		For $i = 1 To $aColor[0][0]
			If ($sChar == $aColor[$i][0]) Then
				Return $aColor[$i][1]
			EndIf
		Next
	Endif
EndFunc

Жаль нельзя добавить более одного изображения, рег. выражения не то возвращают...
 

---Zak---

Скриптер
Сообщения
438
Репутация
113
2 Viktor1703
Жаль нельзя добавить более одного изображения, рег. выражения не то возвращают...
А если вот как-нибудь так (в регулярных не очень силен):

Код:
$sBody = StringRegExpReplace($sXpi, '(?is)@\s+' & $sName & '[\s+|\n|\r]+{[\s+|\n|\r]+(.*?)[\s+|\n|\r]+}', '$1')

заменить на
Код:
$sBody = StringRegExpReplace($sXpi, '(?is).*@\s+' & $sName & '[\s+|\n|\r]+{[\s+|\n|\r]+(.*?)[\s+|\n|\r]+}.*', '$1')



Пример:
Код:
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$xpi =  '@ AutoIt' & @CRLF & _
        '{' & @CRLF & _
        '   COLORREF . 0x00000000' & @CRLF & _
        '   COLORREF # 0xFF606060' & @CRLF & _
        '   SIZE     41 5' & @CRLF & _
        '   ROW ".####..##..##.######..####..######.######"' & @CRLF & _
        '   ROW "##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "######.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "##..##..####....##....####..######...##.."' & @CRLF & _
        '}' & @CRLF & _
		'@ MyIcon' & @CRLF & _
        '{' & @CRLF & _
        '   COLORREF . 0x00000000' & @CRLF & _
        '   COLORREF # 0xFFFF0000' & @CRLF & _
        '   COLORREF $ 0xFFB20000' & @CRLF & _
        '   SIZE     20 20' & @CRLF & _
        '   ROW "$$$$................"' & @CRLF & _
        '   ROW "$$$....######......."' & @CRLF & _
        '   ROW "$$...##########....."' & @CRLF & _
        '   ROW "$...####....####...."' & @CRLF & _
        '   ROW "...###........###..."' & @CRLF & _
        '   ROW "..#####........###.."' & @CRLF & _
        '   ROW "..##.###........##.."' & @CRLF & _
        '   ROW ".###..###.......###."' & @CRLF & _
        '   ROW ".##....###.......##."' & @CRLF & _
        '   ROW ".##.....###......##."' & @CRLF & _
        '   ROW ".##......###.....##."' & @CRLF & _
        '   ROW ".##.......###....##."' & @CRLF & _
        '   ROW ".###.......###..###."' & @CRLF & _
        '   ROW "..##........###.##.."' & @CRLF & _
        '   ROW "..###........#####.."' & @CRLF & _
        '   ROW "...###........###..."' & @CRLF & _
        '   ROW "....####....####...$"' & @CRLF & _
        '   ROW ".....##########...$$"' & @CRLF & _
        '   ROW ".......######....$$$"' & @CRLF & _
        '   ROW "................$$$$"' & @CRLF & _
        '}'
$hForm = GUICreate('')
$iPic = GUICtrlCreatePic('', 20, 20, 41, 5)
GUICtrlPic_SetXpiImage($iPic, $xpi, 'AutoIt')
$iPic = GUICtrlCreatePic('', 20, 40, 41, 5)
GUICtrlPic_SetXpiImage($iPic, $xpi, 'MyIcon')
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
Wend

Func GUICtrlPic_SetXpiImage($iCtrl, $sXpi, $sName)

    Local $sBody, $aColor, $aSize, $aImage, $aSet[1][1], $hImage, $hGraphic, $hBmp, $hBitmap, $hPrev

    If (Not IsHWnd($iCtrl)) Then
        $iCtrl = GUICtrlGetHandle($iCtrl)
    EndIf

;~ 	$sBody = StringRegExpReplace($sXpi, '(?is)@\s+' & $sName & '[\s+|\n|\r]+{[\s+|\n|\r]+(.*?)[\s+|\n|\r]+}', '$1')
    $sBody = StringRegExpReplace($sXpi, '(?is).*@\s+' & $sName & '[\s+|\n|\r]+{[\s+|\n|\r]+(.*?)[\s+|\n|\r]+}.*', '$1')
    If ((Not $sBody) Or @error) Then
        Return SetError(1, 0, False)
    EndIf

    $aColor = StringRegExp($sBody, '(?i)COLORREF\s+(.*?)\s+(.*?)[\s+|\n|\r]+', 3)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(2, 0, False)
    EndIf

    $aColor = __xpi_to2d($aColor)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(3, 0, False)
    EndIf

    $aSize = StringRegExp($sBody, '(?i)SIZE\s+(\d+?)\s+(\d+?)[\s+|\n|\r]+', 3)
    If (@error Or (Not IsArray($aSize)) Or (UBound($aSize) <> 2)) Then
        Return SetError(4, 0, False)
    EndIf

    $aImage = StringRegExp($sBody, '(?is)ROW\s+"(.*?)"', 3)
    If (@error Or (Not IsArray($aImage))) Then
        Return SetError(5, 0, False)
    EndIf

    If (UBound($aImage) == $aSize[1]) Then
        ReDim $aSet[$aSize[1]][$aSize[0]]
        For $i = 0 To (UBound($aImage) - 1)
            For $l = 0 To ($aSize[0] - 1)
                If (StringLen($aImage[$i]) <> $aSize[0]) Then
                    Return SetError(6, 0, False)
                EndIf
                $aSet[$i][$l] = StringMid($aImage[$i], ($l + 1), 1)
            Next
        Next
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromScan0($aSize[0], $aSize[1])
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
        $hBmp = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphic)
        For $i = 0 To $aSize[1] - 1
            For $l = 0 To $aSize[0] - 1
                _GDIPlus_BitmapSetPixel($hBmp, $l, $i, __xpi_getcolor($aColor, $aSet[$i][$l]))
            Next
        Next
        _GDIPlus_GraphicsDrawImage($hGraphic, $hBmp, 0, 0)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hPrev = _SendMessage($iCtrl, 0x0172, 0, $hBitmap)
        If $hPrev Then
            _WinAPI_DeleteObject($hPrev)
        EndIf
        $hPrev = _SendMessage($iCtrl, 0x0173)
        If ($hPrev <> $hBitmap) Then
            _WinAPI_DeleteObject($hBitmap)
        EndIf
        _GDIPlus_BitmapDispose($hBmp)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_BitmapDispose($hImage)
        _GDIPlus_Shutdown()
    EndIf

    Return False
EndFunc

Func __xpi_to2d($aColor)

    Local $aTemp[1][2]

    If (IsArray($aColor) And UBound($aColor)) Then
        For $i = 0 To UBound($aColor) - 1 Step 2
            If (($aColor[$i] == '') Or (StringLen($aColor[$i]) > 1)) Then
                Return SetError(1, 0, 0)
            EndIf
            If (($aColor[$i + 1] == '') Or (StringRegExp($aColor[$i + 1], '0x.{8}') <> 1)) Then
                Return SetError(2, 0, 0)
            EndIf
            $aTemp[0][0] += 1
            ReDim $aTemp[$aTemp[0][0] + 1][UBound($aTemp, 2)]
            $aTemp[$aTemp[0][0]][0] = $aColor[$i]
            $aTemp[$aTemp[0][0]][1] = $aColor[$i + 1]
        Next
        Return $aTemp
    EndIf
    Return False
EndFunc

Func __xpi_getcolor($aColor, $sChar)
    If IsArray($aColor) Then
        For $i = 1 To $aColor[0][0]
            If ($sChar == $aColor[$i][0]) Then
                Return $aColor[$i][1]
            EndIf
        Next
    Endif
EndFunc
 

Z_Lenar

Продвинутый
Сообщения
209
Репутация
52
Viktor1703
Переделал:
Код:
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$xpi =  '@ AutoIt' & @CRLF & _
        '{' & @CRLF & _
        '   COLORREF . 0x00000000' & @CRLF & _
        '   COLORREF # 0xFF606060' & @CRLF & _
        '   SIZE     41 5' & @CRLF & _
        '   ROW ".####..##..##.######..####..######.######"' & @CRLF & _
        '   ROW "##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "######.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "##..##.##..##...##...##..##...##.....##.."' & @CRLF & _
        '   ROW "##..##..####....##....####..######...##.."' & @CRLF & _
        '}' & @CRLF & _
'@ MyIcon' & @CRLF & _
        '{' & @CRLF & _
        '   COLORREF . 0x00000000' & @CRLF & _
        '   COLORREF # 0xFFFF0000' & @CRLF & _
        '   COLORREF $ 0xFFB20000' & @CRLF & _
        '   SIZE     20 20' & @CRLF & _
        '   ROW "$$$$................"' & @CRLF & _
        '   ROW "$$$....######......."' & @CRLF & _
        '   ROW "$$...##########....."' & @CRLF & _
        '   ROW "$...####....####...."' & @CRLF & _
        '   ROW "...###........###..."' & @CRLF & _
        '   ROW "..#####........###.."' & @CRLF & _
        '   ROW "..##.###........##.."' & @CRLF & _
        '   ROW ".###..###.......###."' & @CRLF & _
        '   ROW ".##....###.......##."' & @CRLF & _
        '   ROW ".##.....###......##."' & @CRLF & _
        '   ROW ".##......###.....##."' & @CRLF & _
        '   ROW ".##.......###....##."' & @CRLF & _
        '   ROW ".###.......###..###."' & @CRLF & _
        '   ROW "..##........###.##.."' & @CRLF & _
        '   ROW "..###........#####.."' & @CRLF & _
        '   ROW "...###........###..."' & @CRLF & _
        '   ROW "....####....####...$"' & @CRLF & _
        '   ROW ".....##########...$$"' & @CRLF & _
        '   ROW ".......######....$$$"' & @CRLF & _
        '   ROW "................$$$$"' & @CRLF & _
        '}'

$hForm = GUICreate('')
$iPic = GUICtrlCreatePic('', 20, 20, 20, 20)
GUICtrlPic_SetXpiImage($iPic, $xpi, 'MyIcon')
$iPic1 = GUICtrlCreatePic('', 50, 20, 41, 5)
GUICtrlPic_SetXpiImage($iPic1, $xpi, 'AutoIt')
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
Wend

Func GUICtrlPic_SetXpiImage($iCtrl, $sXpi, $sName)

    Local $sBody, $aColor, $aSize, $aImage, $aSet[1][1], $hImage, $hGraphic, $hBmp, $hBitmap, $hPrev

    If (Not IsHWnd($iCtrl)) Then
        $iCtrl = GUICtrlGetHandle($iCtrl)
    EndIf

    $sBody = StringRegExpReplace($sXpi, '(?is).*[email protected]\s+' & $sName & '[^{]+\{([^}]+)\}.*', '$1')
    If ((Not $sBody) Or @error) Then
        Return SetError(1, 0, False)
    EndIf

    $aColor = StringRegExp($sBody, '(?i)COLORREF\s+([[:punct:]]+)\s+(\w+)', 3)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(2, 0, False)
    EndIf

    $aColor = __xpi_to2d($aColor)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(3, 0, False)
    EndIf

    $aSize = StringRegExp($sBody, '(?i)SIZE\s+(\d+)\s+(\d+)', 3)
    If (@error Or (Not IsArray($aSize)) Or (UBound($aSize) <> 2)) Then
        Return SetError(4, 0, False)
    EndIf

    $aImage = StringRegExp($sBody, '(?is)ROW\s+"([^"]*)', 3)
    If (@error Or (Not IsArray($aImage))) Then
        Return SetError(5, 0, False)
    EndIf

    If (UBound($aImage) == $aSize[1]) Then
        ReDim $aSet[$aSize[1]][$aSize[0]]
        For $i = 0 To (UBound($aImage) - 1)
            For $l = 0 To ($aSize[0] - 1)
                If (StringLen($aImage[$i]) <> $aSize[0]) Then
                    Return SetError(6, 0, False)
                EndIf
                $aSet[$i][$l] = StringMid($aImage[$i], ($l + 1), 1)
            Next
        Next
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromScan0($aSize[0], $aSize[1])
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
        $hBmp = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphic)
        For $i = 0 To $aSize[1] - 1
            For $l = 0 To $aSize[0] - 1
                _GDIPlus_BitmapSetPixel($hBmp, $l, $i, __xpi_getcolor($aColor, $aSet[$i][$l]))
            Next
        Next
        _GDIPlus_GraphicsDrawImage($hGraphic, $hBmp, 0, 0)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hPrev = _SendMessage($iCtrl, 0x0172, 0, $hBitmap)
        If $hPrev Then
            _WinAPI_DeleteObject($hPrev)
        EndIf
        $hPrev = _SendMessage($iCtrl, 0x0173)
        If ($hPrev <> $hBitmap) Then
            _WinAPI_DeleteObject($hBitmap)
        EndIf
        _GDIPlus_BitmapDispose($hBmp)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_BitmapDispose($hImage)
        _GDIPlus_Shutdown()
    EndIf

    Return False
EndFunc

Func __xpi_to2d($aColor)

    Local $aTemp[1][2]

    If (IsArray($aColor) And UBound($aColor)) Then
        For $i = 0 To UBound($aColor) - 1 Step 2
            If (($aColor[$i] == '') Or (StringLen($aColor[$i]) > 1)) Then
                Return SetError(1, 0, 0)
            EndIf
            If (($aColor[$i + 1] == '') Or (StringRegExp($aColor[$i + 1], '0x.{8}') <> 1)) Then
                Return SetError(2, 0, 0)
            EndIf
            $aTemp[0][0] += 1
            ReDim $aTemp[$aTemp[0][0] + 1][UBound($aTemp, 2)]
            $aTemp[$aTemp[0][0]][0] = $aColor[$i]
            $aTemp[$aTemp[0][0]][1] = $aColor[$i + 1]
        Next
        Return $aTemp
    EndIf
    Return False
EndFunc

Func __xpi_getcolor($aColor, $sChar)
    If IsArray($aColor) Then
        For $i = 1 To $aColor[0][0]
            If ($sChar == $aColor[$i][0]) Then
                Return $aColor[$i][1]
            EndIf
        Next
    Endif
EndFunc
 
Автор
Viktor1703

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
408
Вот такая вот картинка получилась :smile:

Код:
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$xpi =  '@ Girl' & @CRLF & _
		'{' & @CRLF & _
		'   COLORREF , 0xFFE9E1D9' & @CRLF & _
		'   COLORREF ~ 0xFFE2DAD0' & @CRLF & _
		'   COLORREF : 0xFFE1D8CE' & @CRLF & _
		'   COLORREF . 0xFFEBDCDB' & @CRLF & _
		'   COLORREF + 0xFFD9D5D3' & @CRLF & _
		'   COLORREF ? 0xFFD9D5D3' & @CRLF & _
		'   COLORREF I 0xFF9E908A' & @CRLF & _
		'   COLORREF 7 0xFF82746F' & @CRLF & _
		'   COLORREF $ 0xFF7B6C66' & @CRLF & _
		'   COLORREF Z 0xFF73615C' & @CRLF & _
		'   COLORREF O 0xFF746059' & @CRLF & _
		'   COLORREF 8 0xFF4E3D38' & @CRLF & _
		'   COLORREF = 0xFFCCB18D' & @CRLF & _
		'   COLORREF D 0xFF433530' & @CRLF & _
		'   COLORREF N 0xFF423934' & @CRLF & _
		'   COLORREF M 0xFF2C231C' & @CRLF & _
		'   SIZE     100 64' & @CRLF & _
		'   ROW ",,~:::::.:,,,,,,,::+++?II7$ZZZZ$7ZO$II7$88888OOZZZZZZ$$$$77$ZOZZ77III777II?++=:~=:::,,:+?==?Z7?+~~~,"' & @CRLF & _
		'   ROW ",:::,:,,.,,.,,:::+==+I$$$O88OZZOZ$$Z7I7Z8DDDDD888OZ$$7$$$$7777$Z$7IIIII77I??++~==~:,,:~~~I+~==I++=:,"' & @CRLF & _
		'   ROW ",,::,,,,,,,:::,,:=?I7O8DDNNND8OZ$$O87I7$ODND888888OOOOZ$$Z$$$$$$ZZ$7II7???II?+==~:::==~=II+~~~+:,,::"' & @CRLF & _
		'   ROW ",,,:,,,,,:::,,,:~+?$O8DNMMND8OZ$77O88I?7Z8DDD8OOOOZZZOOOZ$$ZZ$$$$$ZZ7?II????I+==~~~~~==+?~~~~~+=~~:,"' & @CRLF & _
		'   ROW ",:~:,.,::::,,,:~II$8NMMMMMNDO$$OOOZ$8O$ZO8DD8OOOO$$7$$$$ZOZ7$$$$7$77$7?????++++===~::~=:~+=:::=:,,,,"' & @CRLF & _
		'   ROW "::,,,,::,::,,:~?I$ODNMMMMMN8OZO8DDD8O8OZOOD88OOZZ$$777$$7$Z$7777$$$777I??+??+++=======++~::~=::,,:::"' & @CRLF & _
		'   ROW ",.,,,:::::,,:~I$$ODMMMMMMNNDD88DDDD88OZ$7O8D8OZZ$7IIII777I7$7I7IIIIII7III?+++++==+=+++I+:~~==,.,,:~:"' & @CRLF & _
		'   ROW ",,,,:::::,,:==?$O8NMMMMNND8DDDDD88OOOZ7II$O88OOZ$$7???IIII?I7III???IIIIII?++++======??+=:~~~:,:,:~=~"' & @CRLF & _
		'   ROW ",.,::::~::::=+7ODNMMMMMND8OOO888Z7I??+==?I$Z$7OOZZ$7$?+III++?7?+?=?+??I7III+===~~++==+++=~,.,,,,,~=+"' & @CRLF & _
		'   ROW ",,,~~~~~:::~+IZDNMMMMMMNN88OOOOZ7?+===~~=+IZO?+7Z$$777++??+=+I?=++=++??IIII?=~=+~~====?+=~,,..,::::~"' & @CRLF & _
		'   ROW ",,:~??+=::~=I$8NMMMMMMNND8Z$7I?+=~~~::::::~+IZ$?+I$7II?~++==+??====~++???III?~:~=~~==~==~:,,.,,:,,,,"' & @CRLF & _
		'   ROW ",,====~~~:~+7O8NMMMMND88OZ$I?==~~~~::::::::~=IZ$I=?777I~=+==++I+~==~=++????II+~:~=~=====~:,,,,:,,:::"' & @CRLF & _
		'   ROW ",,:::~~==+?7OD$ZMMM8ZII?+++==~~~~~~::~~~::~~~:=I$Z7=?ZZ=~+=+++I?==+=~==+????II+~:~=====~::::,,,,::::"' & @CRLF & _
		'   ROW ":::=~~~==??$8NDNMMDZ7??++====~~~~~~~~:~=~::::::=?$Z7+7$=~+=+=+II====~~==+???II?=:~==~++=~:::::,,::~~"' & @CRLF & _
		'   ROW ",,,:=?~=+I$O8NDMMNO7?+++====~~~~~~==?==~:::::::::~?ZO$Z?:==++++7++===:~~=++??77+~:~===+=~:::,,,::==~"' & @CRLF & _
		'   ROW ",,::::==?I$O8MNMMNO7?++=====~~~~=++?=~~~::::::::::~IZO$?~+=++?+I?+===::~~===++7?=::~===+~:::,,,:::::"' & @CRLF & _
		'   ROW ",,,,:==+?$OODNMMMDZ7?++=====~~~~=+=~~~:~::::::,,,::~IOO7==+=+??+I=+===::~~~~~~=II~::~==++=:::,:~:::~"' & @CRLF & _
		'   ROW ",,:,:~=+I$OO8DDMMDO7?++=====~~~~~~~:::::::::,,,,,,::=7Z7+=+~???+I=++==:,:~~:~~~+I+:::==+++~:::::,::~"' & @CRLF & _
		'   ROW ",,,:~++?7ZOO8DNMMD8ZI++=====~~~~~~~~::::::::,,,,,,::~=77+=+~?+?I?++++?~::::::::~=7=::~=++?I====+:::,"' & @CRLF & _
		'   ROW "::,~=+?I7ZZO8DMMMN8ZI++=====~~~~~~~~~::::::,,,,,,,,::~?I+==~?+?7??+?+I=::::~=~:~~?+~::~++?7I=~:~~:,:"' & @CRLF & _
		'   ROW "::~++=?I7$7Z88NMMNDO7?++====~~~~~~~~:::::::,,,,,.,,,,:~==~==+++I?++I+I+~~::~=?=~===~::~=+?$$I=~~::::"' & @CRLF & _
		'   ROW ",,~+==+I7$$Z88NMMNDO$??++===~~~~~~~~:::::::::,:,.,,,,::~=~==+++??+?I+??=~:::=+?+===~~~:~=+7$7+=~::,,"' & @CRLF & _
		'   ROW "~::~?+?II$$Z8ODMMMDO$I??+====~~~~~~~~~~~=+7O88$I?+==?I?==~+=+?++I+?III?+==~::+I++?+===~:~=I77+~::,,,"' & @CRLF & _
		'   ROW ":,::~=I7I$$ZOOOMMMN8Z$I??+====~~~~~~==+IODDO7?=::,,,:=I?+==+=?++I?+?7I7++=~~~=I7+??++=~:~=+77?=::,,,"' & @CRLF & _
		'   ROW ",::::~+III7$ZOONMMNNMMNNDOO$I+=~~~~~$MM8$77$OOOOZ$III?+++=++=??=??++?IZ??+==+=?$7+7?+?=~~~=?7?+=~~:,"' & @CRLF & _
		'   ROW ":,,:~=+??7I7ZOZDMMMNNMMMMMMMN7=~~~~~?O$7I$ZDDDDNNMMMN8Z7I=+==??+??+++IZ7I?=?+++7$II?+??=~~=+??+~:::,"' & @CRLF & _
		'   ROW "...,,~=+?7ZI7$78NMM8NNNMMMMMMDI=~~:::=+IIONMNMMMMMMMMMNZ?=+==++++??=?+$$I?+???++?77I++7I+=~=+??=~~=="' & @CRLF & _
		'   ROW ",,,,:+++?7877Z7ONMMNMMMMMMMMMMZ+=~::::~+?$D8ZZOZOO$8D87?=~=~~==++??+??7Z7I+???I??I7I+=7$?====??=~~::"' & @CRLF & _
		'   ROW ".,.ON~?I+?$I7Z7$NMMMMMMMMMMMMMMO+:,,,,,:=II???I777I?++=~~~~~~~=+++++++I$77I=??77?7$I+=?$$?=++??=~::,"' & @CRLF & _
		'   ROW ",,,ZN~=??I7?7ZZ7D8MMMMMMMNNDMMMN?:..,,,:~=+?IIII??==~~=~=~~~~~~+=++?++I$777++?7$+I$7?=+ZZ7++++I=~::,"' & @CRLF & _
		'   ROW ",,:Z+,~=+IOI?Z87OD8MMMMMN8OZZZ8NI,.....,,::~~~~~:::::=+=~~:~~~~==++?++IZ$$7?++?7??$$I==?Z$?+++?+~~::"' & @CRLF & _
		'   ROW "++?7Z:~==?ZI+$Z$$8MMMMMND8OZ$7ZD+,....,,,,::::::::::~=?==~:~~~===+=+?+I$Z$7I???7II77?~=?$$?+++?+=~~:"' & @CRLF & _
		'   ROW ":::ZN,:===??=I$ZZ8MMMMD88OZ$$$ZZ~...,,,,,,,,::::::::~~+=~~~~~~==~====+I7$$$I?I?II$7$I=~+$ZI++++?+=~:"' & @CRLF & _
		'   ROW "=,,ZN::~~=$+=?$$ZONMMMD8OZ$$$$Z7:,..,,,,,,,,:::::::::~++~=~~~~==~~~==+I$$$$7?I?II$$$I+~+7ZI+==+??=~~"' & @CRLF & _
		'   ROW "~::Z7:~~~?II==I7ZO8NDNDOOZ$$$$$I:....,,,,,,,:::::::::::~==:~~~=~~~~==+7ZZ$$7?I?II$$77+=~I$7+===+?++="' & @CRLF & _
		'   ROW ",~=$O?~~=OO7==+7ZOOOZDD8OZ$$$$$?:.....,,,,::,::::::::::~=::~~~==~=~==+I$$$$7???II$$77++=+$$+===+??++"' & @CRLF & _
		'   ROW ",+===~::==~==~=+I$Z88MMNOZ$$$$$=:........,:~::::::::::::~:~~~~~=~=~===IZZ$7II??II7$77?++=?I+====+??+"' & @CRLF & _
		'   ROW ".,~~+:,:=====~==?7$OZDMNDZ$$$Z$+:,........,:::::::::::::::~~~~~=~=====?ZZ$I?I?+??$7$7I+?+=??==~~=+?+"' & @CRLF & _
		'   ROW ",,:::::~==+=====+I7$8NNMM8Z$$Z8$+~:::~+=~:,,,::::::::::::::~~~~======+IZ$7????+I?$I$$$?II??++=~~~=++"' & @CRLF & _
		'   ROW "..,,,,,~==+===~==?I$ZDNNMNZZ$ZDD$+~~+7$Z?:.,,,,::::::::::::~~~~======+I$7I+???+?I$I$$$II7II++=~~~=+?"' & @CRLF & _
		'   ROW "~:===:::~=+=++==++?7$ODNNMDZZZDNDD8ZI=,,.,,,,,,,,::::::::::~~~~==+=++?77??+?++=+?7?$$7I7$$7I+=~~~~=+"' & @CRLF & _
		'   ROW ":=+??=~~:=++++==++?I$Z8DNMMOZO888D8Z?+:,,,,,,,,,,,::::::::::~~~==+++??I??+++++~=I7I77I777$7I++=~~~=+"' & @CRLF & _
		'   ROW "=~~=?~:::~??+?+=+?=?7$O8DNMM8OOO88Z+:~~,.,,,,,,,,:~~~:::::::~===++++I?++++++=+~~?I?7?III777I++~~==~="' & @CRLF & _
		'   ROW ":~+?=::~~=+???+++?++I$O8DNMMDOOOOO$=,,::,,,::::~=?I+~~::::::~===++??I+++++?++=~~?I+7???I777I++=~===="' & @CRLF & _
		'   ROW "::===~~~~=???????I++?7ZO8DNMMNOOOO888DDNN87+~:,,,,:~~::::::~==++??III+????++==~:=III==+?II7?+==~~==="' & @CRLF & _
		'   ROW ":,~?I~~~~=+?????II?+?7$ZODNMMMNOO8MMN8O$I=::::::::~~~:::~~~~~=++???II??I?++?==~:~?I?==++?II?+===~==="' & @CRLF & _
		'   ROW "::++~=~==++=????II7+??7$$ODNMMMMDOOOO7IIII+=~~===~~?==?==~~~=++??I?I+???+++?+=~,:+II+==+??II+=~~~~~="' & @CRLF & _
		'   ROW ":~+~~~~~~===+???II7???I7$Z8DMMMMMDOZZZ$$$$7?+===~~~7OI?+~~~==+?I?I?I++???++?+=~::+II+===??II++~~==~~"' & @CRLF & _
		'   ROW ",=+:~~,:~~~=+????77I+?+?I$ODNMMMMMMDZZZZ$I+==~~~~::=+?:~~=++I?II??II?+?I?++++=~::=?7+=~=??II?+=~=~~:"' & @CRLF & _
		'   ROW ",,...,,,====++?+?III++++?7Z8NNMMMMMM8ZZ$I+=~~~~~~~:~==~~=+??$III?????+?I?++?+=~::~?7+=~~++I??==~~~::"' & @CRLF & _
		'   ROW ",,,,.,~::~=~+++=+??7?==++?$O8DNMMMMMMDZ$I+=~~:::~~==~==I7$7I77III???++?I?+=?+=~~::???=~:~=???+~~~~~:"' & @CRLF & _
		'   ROW "::,,,.,:~~~=+++++++I?====+IOO8DMMNMMMMO7I+==~~~~~~~~=+I$ZZ7?7IIII???+=+7?+=?+~:~~~=?+~::~=++?+~:~~~~"' & @CRLF & _
		'   ROW "~=:,,,:~::~~++++=+=?I===~=?$ZZONMMNMMMMN7?+++++++??7ZOOOZ7I???I???++?~=?++=?+~:~::~?+=:,:~~=?+~::~~~"' & @CRLF & _
		'   ROW ",~~~,,,:~:~===++==~=?+=~~=+7$$ZDNMMMMMMMN8$IIII77$Z888OZ$7I??+I???+++~=?++=++=:~~::++=:,::~~=+~~::~~"' & @CRLF & _
		'   ROW "~~=~::,,,:~~===++~:~+?=~:~=+I77Z88MMNNMNMMMMNNNNDD8OOZZ$7??+?+???++++~~??+=~==~~~~:=+=~,::::~=~~:::~"' & @CRLF & _
		'   ROW "=~=~~=~:::~:====+~,:=?=~::=+?I7Z8ONMNNNNNNMNNNND88ZZ$$77I?++++???+=+?~~??++==~~~~~~~==~:::::~~~~~::~"' & @CRLF & _
		'   ROW ":~===~=~=:~~==~=+~,,=++~,,~~+?I$8O8DNNDNNDDND8OOOZ$7IIII??+=++++?+==?~~+??+=+~=~==~====~::::::====~~"' & @CRLF & _
		'   ROW ",:~~:~,,,:===~~~==,,=++=:,:~==?7ZZO8DN8DND8O8O$Z$$I??+++++====++?=~~?+:+??+=+=~===~+====:,~:::++==~:"' & @CRLF & _
		'   ROW "..,~....,:~==~~~~=,,~?=~:,,:~~+?7$7Z8OOZOOO8Z$7III?+========~==+++~~?I:~+?+?+?=====++~~~:,::~~++=~~,"' & @CRLF & _
		'   ROW "::,,..,,:~===~~~~~:,~7?=:,,,~:=+I77$ZOO$Z$ZZO7?I?++=~~~=~===~===+?~:+I=:=+=++?+=====?+~~:::~~=?+~~:,"' & @CRLF & _
		'   ROW "=,,,..,,::~==~:~=~:::+I?=:,::~~~+?I777$$7I7$Z$I+===~~~~~~~~~~~~~=+=~=I+~~==+I?+===+=??~~:~~===?+~:,,"' & @CRLF & _
		'   ROW "~,.,,.,,:~~==~::==:::~+?+~:::~~~=++I7I77I?I7Z$I+=~~~:::~~~~~~~~~===~=??~~~=+I??+=++=??=~:~===+++~:,,"' & @CRLF & _
		'   ROW ",,,~::~+??++==~:~+=~::~+I?=~:~~~===??+?I++?I$7?+==::::::::~~~~~~=~=~=??====++?+++++++?==~~+==+++~::~"' & @CRLF & _
		'   ROW ",,:=+==?I7I=~=~~~==~~~~=+I+~~~=~~=~++=??++??II?+==::::,,:::~~~~~=~~~=+I+==+?+?+++??+++===~+=+??+=~~~"' & @CRLF & _
		'}'

$hForm = GUICreate('')
$iPic1 = GUICtrlCreatePic('', 20, 20, 100, 64)
$iRes = GUICtrlPic_SetXpiImage($iPic1, $xpi, 'Girl')

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
Wend

Func GUICtrlPic_SetXpiImage($iCtrl, $sXpi, $sName)

    Local $sBody, $aColor, $aSize, $aImage, $aSet[1][1], $hImage, $hGraphic, $hBmp, $hBitmap, $hPrev

    If (Not IsHWnd($iCtrl)) Then
        $iCtrl = GUICtrlGetHandle($iCtrl)
    EndIf

    $sBody = StringRegExpReplace($sXpi, '(?is).*[email protected]\s+' & $sName & '[^{]+\{([^}]+)\}.*', '$1')
    If ((Not $sBody) Or @error) Then
        Return SetError(1, 0, False)
    EndIf

    $aColor = StringRegExp($sBody, '(?i)COLORREF\s+([^\s]+)\s+(\w+)', 3)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(2, 0, False)
    EndIf

    $aColor = __xpi_to2d($aColor)
    If (@error Or (Not IsArray($aColor))) Then
        Return SetError(3, 0, False)
    EndIf

    $aSize = StringRegExp($sBody, '(?i)SIZE\s+(\d+)\s+(\d+)', 3)
    If (@error Or (Not IsArray($aSize)) Or (UBound($aSize) <> 2)) Then
        Return SetError(4, 0, False)
    EndIf

    $aImage = StringRegExp($sBody, '(?is)ROW\s+"([^"]*)', 3)
    If (@error Or (Not IsArray($aImage))) Then
        Return SetError(5, 0, False)
    EndIf

    If (UBound($aImage) == $aSize[1]) Then

        ReDim $aSet[$aSize[1]][$aSize[0]]
        For $i = 0 To (UBound($aImage) - 1)
            For $l = 0 To ($aSize[0] - 1)
                If (StringLen($aImage[$i]) <> $aSize[0]) Then
                    Return SetError(6, 0, False)
                EndIf
                $aSet[$i][$l] = StringMid($aImage[$i], ($l + 1), 1)
            Next
        Next
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromScan0($aSize[0], $aSize[1])
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
        $hBmp = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphic)
        For $i = 0 To $aSize[1] - 1
            For $l = 0 To $aSize[0] - 1
                _GDIPlus_BitmapSetPixel($hBmp, $l, $i, __xpi_getcolor($aColor, $aSet[$i][$l]))
            Next
        Next
        _GDIPlus_GraphicsDrawImage($hGraphic, $hBmp, 0, 0)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hPrev = _SendMessage($iCtrl, 0x0172, 0, $hBitmap)
        If $hPrev Then
            _WinAPI_DeleteObject($hPrev)
        EndIf
        $hPrev = _SendMessage($iCtrl, 0x0173)
        If ($hPrev <> $hBitmap) Then
            _WinAPI_DeleteObject($hBitmap)
        EndIf
        _GDIPlus_BitmapDispose($hBmp)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_BitmapDispose($hImage)
        _GDIPlus_Shutdown()
    EndIf

    Return False
EndFunc

Func __xpi_to2d($aColor)

    Local $aTemp[1][2]

    If (IsArray($aColor) And UBound($aColor)) Then
        For $i = 0 To UBound($aColor) - 1 Step 2
            If (($aColor[$i] == '') Or (StringLen($aColor[$i]) > 1)) Then
                Return SetError(1, 0, 0)
            EndIf
            If (($aColor[$i + 1] == '') Or (StringRegExp($aColor[$i + 1], '0x.{8}') <> 1)) Then
                Return SetError(2, 0, 0)
            EndIf
            $aTemp[0][0] += 1
            ReDim $aTemp[$aTemp[0][0] + 1][UBound($aTemp, 2)]
            $aTemp[$aTemp[0][0]][0] = $aColor[$i]
            $aTemp[$aTemp[0][0]][1] = $aColor[$i + 1]
        Next
        Return $aTemp
    EndIf
    Return False
EndFunc

Func __xpi_getcolor($aColor, $sChar)
    If IsArray($aColor) Then
        For $i = 1 To $aColor[0][0]
            If ($sChar == $aColor[$i][0]) Then
                Return $aColor[$i][1]
            EndIf
        Next
    Endif
EndFunc
 
Верх