Что нового

Не получается отправить Bitmap в GUICtrlCreatePic()

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
410
Или я не внимателен, или что - то ещё, собираю из 9 кусков одну картинку и отправляю в контрол, не становится :scratch:

Код:
#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>
#Include <APIConstants.au3>
#include <WinAPIEx.au3>
#Include <GDIPlus.au3>

_GDIPlus_Startup()

Dim $hPart[10][3]
$hPart[0][0] = UBound($hPart)
$hPart[1][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\1.png")
$hPart[1][1] = _GDIPlus_ImageGetWidth($hPart[1][0])
$hPart[1][2] = _GDIPlus_ImageGetHeight($hPart[1][0])
$hPart[2][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\2.png")
$hPart[2][1] = _GDIPlus_ImageGetWidth($hPart[2][0])
$hPart[2][2] = _GDIPlus_ImageGetHeight($hPart[2][0])
$hPart[3][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\3.png")
$hPart[3][1] = _GDIPlus_ImageGetWidth($hPart[3][0])
$hPart[3][2] = _GDIPlus_ImageGetHeight($hPart[3][0])
$hPart[4][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\4.png")
$hPart[4][1] = _GDIPlus_ImageGetWidth($hPart[4][0])
$hPart[4][2] = _GDIPlus_ImageGetHeight($hPart[4][0])
$hPart[5][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\5.png")
$hPart[5][1] = _GDIPlus_ImageGetWidth($hPart[5][0])
$hPart[5][2] = _GDIPlus_ImageGetHeight($hPart[5][0])
$hPart[6][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\6.png")
$hPart[6][1] = _GDIPlus_ImageGetWidth($hPart[6][0])
$hPart[6][2] = _GDIPlus_ImageGetHeight($hPart[6][0])
$hPart[7][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\7.png")
$hPart[7][1] = _GDIPlus_ImageGetWidth($hPart[7][0])
$hPart[7][2] = _GDIPlus_ImageGetHeight($hPart[7][0])
$hPart[8][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\8.png")
$hPart[8][1] = _GDIPlus_ImageGetWidth($hPart[8][0])
$hPart[8][2] = _GDIPlus_ImageGetHeight($hPart[8][0])
$hPart[9][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\9.png")
$hPart[9][1] = _GDIPlus_ImageGetWidth($hPart[9][0])
$hPart[9][2] = _GDIPlus_ImageGetHeight($hPart[9][0])

$hForm = GUICreate("Example", 400, 300, -1, -1, $WS_POPUP)
$hPic = GUICtrlCreatePic('', 400, 300)
ComposeBitmap($hPic, 400, 300, '', $hPart)
GUISetState()

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd

Func ComposeBitmap($iCtrl, $iWidth, $iHeight, $sTitle, ByRef $hPart)
    Local $hGraphic, $hImage, $hThumb, $hBitmap

    If IsArray($hPart) Then
		ConsoleWrite(111)
        $hImage = _GDIPlus_CreateBitmapFromScan0($iWidth, $iHeight)
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPart[1][0], 0, 0, $hPart[1][1], $hPart[1][2])
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPart[3][0], $iWidth - $hPart[3][1], 0, $hPart[3][1], $hPart[3][2])
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPart[9][0], $iWidth - $hPart[9][1], $iHeight - $hPart[9][2], $hPart[9][1], $hPart[9][2])
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPart[7][0], 0, $iHeight - $hPart[7][2], $hPart[7][1], $hPart[7][2])
        $hThumb = _GDIPlus_GetImageThumbnail($hPart[2][0], $iWidth - ($hPart[1][1] + $hPart[3][1]), $hPart[2][2])
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hThumb, $hPart[1][1], 0, $iWidth - ($hPart[1][1] + $hPart[3][1]), $hPart[2][2])
        _GDIPlus_ImageDispose($hThumb)
        $hThumb = _GDIPlus_GetImageThumbnail($hPart[6][0], $hPart[6][1], $iHeight - ($hPart[3][2] + $hPart[7][2]))
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hThumb, $iWidth - $hPart[6][1], $hPart[3][2], $hPart[6][1], $iHeight - ($hPart[3][2] + $hPart[7][2]))
        _GDIPlus_ImageDispose($hThumb)
        $hThumb = _GDIPlus_GetImageThumbnail($hPart[8][0], $iWidth - ($hPart[7][1] + $hPart[9][1]), $hPart[8][2])
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hThumb, $hPart[7][1], $iHeight - $hPart[8][2], $iWidth - ($hPart[7][1] + $hPart[9][1]), $hPart[8][2])
        _GDIPlus_ImageDispose($hThumb)
        $hThumb = _GDIPlus_GetImageThumbnail($hPart[4][0], $hPart[4][1], $iHeight - ($hPart[1][2] + $hPart[7][2]))
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hThumb, 0, $hPart[1][2], $hPart[4][1], $iHeight - ($hPart[1][2] + $hPart[7][2]))
        _GDIPlus_ImageDispose($hThumb)
        $hThumb = _GDIPlus_GetImageThumbnail($hPart[5][0], $iWidth - ($hPart[4][1] + $hPart[6][1]), $iHeight - ($hPart[1][2] + $hPart[7][2]))
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hThumb, $hPart[4][1], $hPart[1][2], $iWidth - ($hPart[4][1] + $hPart[6][1]), $iHeight - ($hPart[1][2] + $hPart[7][2]))
        _GDIPlus_ImageDispose($hThumb)

        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
		_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($iCtrl), 0x0172, 0, $hBitmap))
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_ImageDispose($hImage)
    EndIf
EndFunc

Func _GDIPlus_CreateBitmapFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipCreateBitmapFromScan0', 'int', $iWidth, 'int', $iHeight, 'int', $iStride, 'int', $iPixelFormat, 'ptr', $pScan0, 'ptr*', 0)
    If (@error) Or ($Ret[0]) Then
        Return SetError(@error, @extended, 0)
    EndIf
    Return $Ret[6]
EndFunc

Func _GDIPlus_GetImageThumbnail($hImage, $iWidth, $iHeight)
    Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageThumbnail', 'ptr', $hImage, 'uint', $iWidth, 'uint', $iHeight, 'ptr*', 0, 'ptr', 0, 'ptr', 0)
    If (@error) Or ($Ret[0]) Then
        Return SetError(@error, @extended, 0)
    EndIf
    Return $Ret[4]
EndFunc




Добавлено:
Сообщение автоматически объединено:

Моя не внимательность

Код:
$hPic = GUICtrlCreatePic('', 400, 300)


Код:
$hPic = GUICtrlCreatePic('', 0, 0, 400, 300)
 
Верх