Jump to content

Recommended Posts

Posted (edited)

If i load a bitmap from memory using _GDIPlus_BitmapCreateFromMemory ( i'll set later to a GuiCtrlCreatePic control ) how can i set the Alpha channel?

Another question is:

I need to put and alfa square under a label text, in this way, but over the background image ( Photoshop )

VZ0zpSI.jpg

PS: MY GUI has Tab control, most of the code is make by @UEZ

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


_GDIPlus_Startup()
Global $myImage = "https://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.png"
Global $hBMPMem = _GDIPlus_BitmapCreateFromMemory(InetRead($myImage), 1) ;this is a GDI bitmap
Global $hGUI = GUICreate("", 300, 300, -1, -1)

GUICtrlCreateTab(0,0,300,300)
GUICtrlCreateTabItem("Test")
Global $iPic = GUICtrlCreatePic("", 50, 50)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hBMPMem)) ; $STM_SETIMAGE
GUICtrlCreateTabItem(""); end tabitem definition
GUICtrlCreateTabItem("Test2")
GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hBMPMem)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

; # 3.3.8.1

Func _GDIPlus_BitmapCreateFromMemory($dImage, $bHBITMAP = False)
    If Not IsBinary($dImage) Then Return SetError(1, 0, 0)
    Local $aResult = 0
    Local Const $dMemBitmap = Binary($dImage) ;load image saved in variable (memory) and convert it to binary
    Local Const $iLen = BinaryLen($dMemBitmap) ;get binary length of the image
    Local Const $GMEM_MOVEABLE = 0x0002
    $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", $iLen) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002)
    If @error Then Return SetError(4, 0, 0)
    Local Const $hData = $aResult[0]
    $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hData)
    If @error Then Return SetError(5, 0, 0)
    Local $tMem = DllStructCreate("byte[" & $iLen & "]", $aResult[0]) ;create struct
    DllStructSetData($tMem, 1, $dMemBitmap) ;fill struct with image data
    DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE
    If @error Then Return SetError(6, 0, 0)
    Local Const $hStream = _WinAPI_CreateStreamOnHGlobal($hData) ;creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    If @error Then Return SetError(2, 0, 0)
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromStream($hStream) ;creates a Bitmap object based on an IStream COM interface
    If @error Then Return SetError(3, 0, 0)
    DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "ulong_ptr", 8 * (1 + @AutoItX64), "uint", 4, "ushort", 23, "uint", 0, "ptr", 0, "ptr", 0, "str", "") ;release memory from $hStream to avoid memory leak
    If $bHBITMAP Then
        Local Const $hHBmp = __GDIPlus_BitmapCreateDIBFromBitmap($hBitmap) ;supports GDI transparent color format
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_BitmapCreateFromMemory

Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $bDeleteOnRelease = True)
    Local $aReturn = DllCall('ole32.dll', 'long', 'CreateStreamOnHGlobal', 'handle', $hGlobal, 'bool', $bDeleteOnRelease, 'ptr*', 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aReturn[0] Then Return SetError(10, $aReturn[0], 0)
    Return $aReturn[3]
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal

Func _GDIPlus_BitmapCreateFromStream($pStream)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

Func __GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $aRet, $tData, $pBits, $hHBitmapv5 = 0
    Local Const $tagBITMAPV5HEADER = 'struct;dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[9];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;endstruct'
    $aRet = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "handle", $hBitmap, "float*", 0, "float*", 0)
    If @error Or $aRet[0] Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, "Scan0")
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate($tagBITMAPV5HEADER)
    DllStructSetData($tBIHDR, "bV5Size", DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, "bV5Width", $aRet[2])
    DllStructSetData($tBIHDR, "bV5Height", $aRet[3])
    DllStructSetData($tBIHDR, "bV5Planes", 1)
    DllStructSetData($tBIHDR, "bV5BitCount", 32)
    DllStructSetData($tBIHDR, "bV5Compression", 0) ; $BI_BITFIELDS = 3, $BI_RGB = 0, $BI_RLE8 = 1, $BI_RLE4 = 2, $RGBA = 0x41424752
    DllStructSetData($tBIHDR, "bV5SizeImage", $aRet[3] * DllStructGetData($tData, "Stride"))
    DllStructSetData($tBIHDR, "bV5AlphaMask", 0xFF000000)
    DllStructSetData($tBIHDR, "bV5RedMask", 0x00FF0000)
    DllStructSetData($tBIHDR, "bV5GreenMask", 0x0000FF00)
    DllStructSetData($tBIHDR, "bV5BlueMask", 0x000000FF)
    DllStructSetData($tBIHDR, "bV5CSType", 2) ; $LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIHDR, "bV5Intent", 4) ; $LCS_GM_IMA = 4
    $hHBitmapv5 = DllCall("gdi32.dll", "ptr", "CreateDIBSection", "hwnd", 0, "struct*", $tBIHDR, "uint", 0, "ptr*", 0, "ptr", 0, "dword", 0)
    If Not @error And $hHBitmapv5[0] Then
        DllCall("gdi32.dll", "dword", "SetBitmapBits", "ptr", $hHBitmapv5[0], "dword", $aRet[2] * $aRet[3] * 4, "ptr", DllStructGetData($tData, "Scan0"))
        $hHBitmapv5 = $hHBitmapv5[0]
    Else
        $hHBitmapv5 = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    $tData = 0
    $tBIHDR = 0
    Return $hHBitmapv5
EndFunc   ;==>__GDIPlus_BitmapCreateDIBFromBitmap

Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted
17 hours ago, Terenz said:

If i load a bitmap from memory using _GDIPlus_BitmapCreateFromMemory ( i'll set later to a GuiCtrlCreatePic control ) how can i set the Alpha channel?

Another question is:

I need to put and alfa square under a label text, in this way, but over the background image ( Photoshop )

VZ0zpSI.jpg

PS: MY GUI has Tab control, most of the code is make by @UEZ

Thanks

 

I understand your first question not really. What do you mean with "set alpha channel"? You want to set a color to transparent?

 

regarding your second question:

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


_GDIPlus_Startup()
Global $myImage = "https://p5.focus.de/img/fotos/crop3196039/3194875996-cv21_9-w630-h270-oc-q75-p5/Preise-Die-Jahresinflationsrate-in-den-USA-war-weniger-als-von-den-meisten-Experten-erwartet.jpg"
Global $hBMPMem = _GDIPlus_BitmapCreateFromMemory(InetRead($myImage)) ;GDI+ bitmap
Global $hGfx = _GDIPlus_ImageGetGraphicsContext($hBMPMem)
_GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 4)
_GDIPlus_GraphicsSetSmoothingMode($hGfx, 4)
_GDIPlus_GraphicsSetTextRenderingHint($hGfx, 4)
Global $hBrush = _GDIPlus_BrushCreateSolid(0x80000000)
_GDIPlus_GraphicsFillRect($hGfx, 100, 50, 300, 150, $hBrush)
Global $hFormat = _GDIPlus_StringFormatCreate()
Global $hFamily = _GDIPlus_FontFamilyCreate("Impact")
Global $hFont = _GDIPlus_FontCreate($hFamily, 24)
_GDIPlus_BrushSetSolidColor($hBrush, 0xF0FFFFFF)
Global $tLayout = _GDIPlus_RectFCreate(150, 100, 300, 50)
_GDIPlus_GraphicsDrawStringEx($hGfx, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)

Global $hBMPMemGDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMPMem)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_ImageDispose($hBMPMem)


Global $hGUI = GUICreate("", 800, 800, -1, -1)

GUICtrlCreateTab(0,0,800,700)
GUICtrlCreateTabItem("Test")
Global $iPic = GUICtrlCreatePic("", 50, 50, 630, 270)

_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hBMPMemGDI)) ; $STM_SETIMAGE
GUICtrlCreateTabItem(""); end tabitem definition
GUICtrlCreateTabItem("Test2")
GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hBMPMemGDI)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Hi UEZ,

I mean the opacity, from 0 to 255, not a single color. Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted
1 hour ago, Terenz said:

Hi UEZ,

I mean the opacity, from 0 to 255, not a single color. Thanks

Try this link then: 

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

@UEZ i don't see nothing, probably i don't have implemented well:

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


_GDIPlus_Startup()
Global $myImage = "https://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.png"
Global $hBMPMem = _GDIPlus_BitmapCreateFromMemory(InetRead($myImage), 1) ;this is a GDI bitmap
Global $hAttribute_Transparent = _GDIPlus_AttributeCreateTransparentBitmap($hBMPMem)

Global $hGUI = GUICreate("", 300, 300, -1, -1)

GUICtrlCreateTab(0,0,300,300)
GUICtrlCreateTabItem("Test")
Global $iPic = GUICtrlCreatePic("", 50, 50)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hAttribute_Transparent)) ; $STM_SETIMAGE
;~ _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hBMPMem)) ; $STM_SETIMAGE
GUICtrlCreateTabItem(""); end tabitem definition
GUICtrlCreateTabItem("Test2")
GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hBMPMem)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func _GDIPlus_AttributeCreateTransparentBitmap($hImage, $fTransparency = 0.25)
    Local Const $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate()
;~     $fTransparency = $fTransparency > 1 ? 1 : $fTransparency < 0 ? 0 : $fTransparency
    Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, $fTransparency * -1)
    Local Const $pColorMatrix = DllStructGetPtr($tColorMatrix)
    _GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, $pColorMatrix)
    Return $hAttribute_Alpha
EndFunc

; # 3.3.8.1

Func _GDIPlus_ColorMatrixCreateTranslate($nRed, $nGreen, $nBlue, $nAlpha = 0)
    Local $iI, $tCM, $aFactors[4] = [$nRed, $nGreen, $nBlue, $nAlpha]
    $tCM = _GDIPlus_ColorMatrixCreateScale(1, 1, 1, 1)
    For $iI = 0 To 3
        DllStructSetData($tCM, "m", $aFactors[$iI], 21 + $iI)
    Next
    Return $tCM
EndFunc   ;==>_GDIPlus_ColorMatrixCreateTranslate

Func _GDIPlus_ColorMatrixCreateScale($nRed, $nGreen, $nBlue, $nAlpha = 1)
    Local $tCM, $tagGDIPCOLORMATRIX = "float m[25];"    ; [5][5] matrix; [0][0] - red, [1][1] - green, [2][2] - blue; [3][3] - alpha, [4][4] - ~should~ be 1
    $tCM = DllStructCreate($tagGDIPCOLORMATRIX)
    DllStructSetData($tCM, "m", $nRed, 1)
    DllStructSetData($tCM, "m", $nGreen, 7)
    DllStructSetData($tCM, "m", $nBlue, 13)
    DllStructSetData($tCM, "m", $nAlpha, 19)
    DllStructSetData($tCM, "m", 1, 25)
    Return $tCM
EndFunc   ;==>_GDIPlus_ColorMatrixCreateScale

Func _GDIPlus_ImageAttributesSetColorMatrix($hImgAttrib, $iColorAdjustType, $pColorMatrix = 0, $pGrayMatrix = 0, $iColorMatrixFlags = 0)
    Local $fEnable = 1, $aResult = DllCall($ghGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr",$hImgAttrib, "int",$iColorAdjustType, _
                                            "int",$fEnable, "ptr",$pColorMatrix, "ptr",$pGrayMatrix, "int",$iColorMatrixFlags)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

Func _GDIPlus_ImageAttributesCreate()
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateImageAttributes", "ptr*", 0)
    Return SetError($aResult[0], 0, $aResult[1])
EndFunc

Func _GDIPlus_BitmapCreateFromMemory($dImage, $bHBITMAP = False)
    If Not IsBinary($dImage) Then Return SetError(1, 0, 0)
    Local $aResult = 0
    Local Const $dMemBitmap = Binary($dImage) ;load image saved in variable (memory) and convert it to binary
    Local Const $iLen = BinaryLen($dMemBitmap) ;get binary length of the image
    Local Const $GMEM_MOVEABLE = 0x0002
    $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", $iLen) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002)
    If @error Then Return SetError(4, 0, 0)
    Local Const $hData = $aResult[0]
    $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hData)
    If @error Then Return SetError(5, 0, 0)
    Local $tMem = DllStructCreate("byte[" & $iLen & "]", $aResult[0]) ;create struct
    DllStructSetData($tMem, 1, $dMemBitmap) ;fill struct with image data
    DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE
    If @error Then Return SetError(6, 0, 0)
    Local Const $hStream = _WinAPI_CreateStreamOnHGlobal($hData) ;creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    If @error Then Return SetError(2, 0, 0)
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromStream($hStream) ;creates a Bitmap object based on an IStream COM interface
    If @error Then Return SetError(3, 0, 0)
    DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "ulong_ptr", 8 * (1 + @AutoItX64), "uint", 4, "ushort", 23, "uint", 0, "ptr", 0, "ptr", 0, "str", "") ;release memory from $hStream to avoid memory leak
    If $bHBITMAP Then
        Local Const $hHBmp = __GDIPlus_BitmapCreateDIBFromBitmap($hBitmap) ;supports GDI transparent color format
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_BitmapCreateFromMemory

Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $bDeleteOnRelease = True)
    Local $aReturn = DllCall('ole32.dll', 'long', 'CreateStreamOnHGlobal', 'handle', $hGlobal, 'bool', $bDeleteOnRelease, 'ptr*', 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aReturn[0] Then Return SetError(10, $aReturn[0], 0)
    Return $aReturn[3]
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal

Func _GDIPlus_BitmapCreateFromStream($pStream)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

Func __GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $aRet, $tData, $pBits, $hHBitmapv5 = 0
    Local Const $tagBITMAPV5HEADER = 'struct;dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[9];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;endstruct'
    $aRet = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "handle", $hBitmap, "float*", 0, "float*", 0)
    If @error Or $aRet[0] Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, "Scan0")
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate($tagBITMAPV5HEADER)
    DllStructSetData($tBIHDR, "bV5Size", DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, "bV5Width", $aRet[2])
    DllStructSetData($tBIHDR, "bV5Height", $aRet[3])
    DllStructSetData($tBIHDR, "bV5Planes", 1)
    DllStructSetData($tBIHDR, "bV5BitCount", 32)
    DllStructSetData($tBIHDR, "bV5Compression", 0) ; $BI_BITFIELDS = 3, $BI_RGB = 0, $BI_RLE8 = 1, $BI_RLE4 = 2, $RGBA = 0x41424752
    DllStructSetData($tBIHDR, "bV5SizeImage", $aRet[3] * DllStructGetData($tData, "Stride"))
    DllStructSetData($tBIHDR, "bV5AlphaMask", 0xFF000000)
    DllStructSetData($tBIHDR, "bV5RedMask", 0x00FF0000)
    DllStructSetData($tBIHDR, "bV5GreenMask", 0x0000FF00)
    DllStructSetData($tBIHDR, "bV5BlueMask", 0x000000FF)
    DllStructSetData($tBIHDR, "bV5CSType", 2) ; $LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIHDR, "bV5Intent", 4) ; $LCS_GM_IMA = 4
    $hHBitmapv5 = DllCall("gdi32.dll", "ptr", "CreateDIBSection", "hwnd", 0, "struct*", $tBIHDR, "uint", 0, "ptr*", 0, "ptr", 0, "dword", 0)
    If Not @error And $hHBitmapv5[0] Then
        DllCall("gdi32.dll", "dword", "SetBitmapBits", "ptr", $hHBitmapv5[0], "dword", $aRet[2] * $aRet[3] * 4, "ptr", DllStructGetData($tData, "Scan0"))
        $hHBitmapv5 = $hHBitmapv5[0]
    Else
        $hHBitmapv5 = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    $tData = 0
    $tBIHDR = 0
    Return $hHBitmapv5
EndFunc   ;==>__GDIPlus_BitmapCreateDIBFromBitmap

In the _GDIPlus_AttributeCreateTransparentBitmap there is a parameter called $hImage but i don't see anything with that name inside that function?

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted

You made some mistakes. Try this:

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


_GDIPlus_Startup()
Global $myImage = "https://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.png"
Global $hBMPMem = _GDIPlus_BitmapCreateFromMemory(InetRead($myImage)) ;use GDI+ bitmap format!!!
Global $hAttribute_Transparent_BMP = _GDIPlus_AttributeCreateTransparentBitmap($hBMPMem, 0.66666)
Global $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hAttribute_Transparent_BMP, 0xFFFFFFFF)

Global $hGUI = GUICreate("", 300, 300, -1, -1)

GUICtrlCreateTab(0,0,300,300)
GUICtrlCreateTabItem("Test")
Global $iPic = GUICtrlCreatePic("", 50, 50)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hGDIBitmap)) ; $STM_SETIMAGE
;~ _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, 0, $hBMPMem)) ; $STM_SETIMAGE
GUICtrlCreateTabItem(""); end tabitem definition
GUICtrlCreateTabItem("Test2")
GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_ImageDispose($hBMPMem)
            _GDIPlus_ImageDispose($hAttribute_Transparent_BMP)
            _WinAPI_DeleteObject($hGDIBitmap)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func _GDIPlus_AttributeCreateTransparentBitmap($hImage, $fTransparency = 0.25)
    Local Const $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate()
;~     $fTransparency = $fTransparency > 1 ? 1 : $fTransparency < 0 ? 0 : $fTransparency
    Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, $fTransparency * -1)
    Local Const $pColorMatrix = DllStructGetPtr($tColorMatrix)
    _GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, $pColorMatrix)
    Local $aDim = _GDIPlus_ImageGetDimension($hImage)
    Local Const $aBitmap = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1])
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($aBitmap)
    _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hImage, 0, 0, $aDim[0], $aDim[1], 0, 0, $aDim[0], $aDim[1], $hAttribute_Alpha)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_ImageAttributesDispose($hAttribute_Alpha)
    Return $aBitmap
EndFunc

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...