Jump to content

ImageList bitmap mask


Go to solution Solved by UEZ,

Recommended Posts

What I need to can set this image with transparency on a button. Should I create a mask or is there another way to do that? Right now the image is on a black background.

#include <GDIPlus.au3>
#include <GUIButton.au3>
#include <GUIImageList.au3>

_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\tm.png')
$hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

$hImageList = _GUIImageList_Create(64,64,6)
_GUIImageList_Add($hImageList,$hHBITMAP)

$hMain = GUICreate("Example")
$hButton = GUICtrlCreateButton('',100,100,74,74,0x0800)
_GUICtrlButton_SetImageList($hButton,$hImageList,4)
$Dummy = GUICtrlCreateInput("",300,300,10,10)
GUISetState(@SW_SHOW,$hMain)

Do
    Sleep(20)
Until GUIGetMsg() = -3

_GUIImageList_Destroy($hImageList)

_WinAPI_DeleteObject($hHBITMAP)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()

Used image: tm.png

msg-34516-0-74412000-1374604487.png

When the words fail... music speaks.

Link to comment
Share on other sites

Try this:

#include <GDIPlus.au3>
#include <GUIButton.au3>
#include <GUIImageList.au3>
#include <WinAPI.au3>

$IMAGE_BITMAP = 0
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\tm.png')
$hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)


$hMain = GUICreate("Example")
$hButton = GUICtrlCreateButton('',100,100,74,74,$BS_BITMAP)
_WinAPI_DeleteObject(GUICtrlSendMsg($hButton, $BM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP))
GUISetState(@SW_SHOW,$hMain)


Do
    Sleep(20)
Until GUIGetMsg() = -3

_WinAPI_DeleteObject($hHBITMAP)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
Exit

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks UEZ, it works fine but can I keep and use somehow the image list because later in script I have to populate a list view with images from the image list, so I am constrained to use masked images from image list.

When the words fail... music speaks.

Link to comment
Share on other sites

Instead of using image list you can create an array with gfx handles which you can use for listview control. Another option is to crop the image or use _GDIPlus_BitmapCreateHBITMAPFromBitmap() with background color...

I will investigate whether it is possible with _GUIImageList_Add() to display transparent images.

Try: _GUICtrlButton_SetImageList($hButton,$hImageList,4) with 4 as parameter (32 bit DIB section)

 

Br,
UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Solution

The embedded image is not a transparent image, it is in bmp format!

Try this:

#include <GUIImageList.au3>
#include <GuiListView.au3>
#include <Memory.au3>
#include <GDIPlus.au3>

$hMain = GUICreate('Example')

_GDIPlus_Startup()
$hBitmap = Bitmap_CreateFromBinaryData(PNG_Data())
$hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

; ImageList
$hImageList = _GUIImageList_Create(64,64,5)
_GUIImageList_Add($hImageList,$hHBITMAP)

; ListView
$hListView = _GUICtrlListView_Create($hMain,'',0,0,400,400,BitOR(0x0000,0x0004,0x4000))
_GUICtrlListView_EnableGroupView($hListView)
_GUICtrlListView_SetView($hListView,1)
_GUICtrlListView_SetIconSpacing($hListView,84,84)
_GUICtrlListView_SetWorkAreas($hListView,10,10,380,380)
_GUICtrlListView_SetImageList($hListView,$hImageList)

; Create a group
_GUICtrlListView_InsertGroup($hListView,0,1,"Countries")
_GUICtrlListView_SetGroupInfo($hListView,1,"Countries",1,0x00000008)

; Add an item
_GUICtrlListView_AddItem($hListView,"Afghanistan",0)
_GUICtrlListView_SetItemGroupID($hListView,0,1)

; Dispose
_WinAPI_DeleteObject($hHBITMAP)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
GUISetState(@SW_SHOW,$hMain)

Do
    Sleep(10)
Until GUIGetMsg() = -3

_GUIImageList_Destroy($hImageList)


; ###########################################################################################
; #                                         FUNCTIONS                                       #
; ###########################################################################################

Func Bitmap_CreateFromBinaryData($bData)
    Local $bBinary = Binary($bData)
    Local $iLen = BinaryLen($bBinary)
    Local $hMem = _MemGlobalAlloc($iLen,$GMEM_MOVEABLE)
    Local $pMem = _MemGlobalLock($hMem)
    Local $tData = DllStructCreate("byte Bitmap[" & $iLen & "]",$pMem)
    DllStructSetData($tData,"Bitmap",$bBinary)
    _MemGlobalUnlock($hMem)
    Local $hStream = _WinAPI_CreateStreamOnHGlobal($pMem,True)
    Local $hBitmap = DllCall("GDIPlus.dll","uint","GdipCreateBitmapFromStream","ptr",$hStream,"int*",0)
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    DllCall("oleaut32.dll","long","DispCallFunc","ptr",$hStream,"dword", 8 + 8 * @AutoItX64,"dword",4,"dword",23,"dword",0,"ptr",0,"ptr",0,"ptr",DllStructGetPtr($tVARIANT))
    Return $hBitmap[2]
EndFunc

Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = 1) ; Created by Yashied
    Local $Ret = DllCall('ole32.dll', 'uint', 'CreateStreamOnHGlobal', 'ptr', $hGlobal, 'int', $fDeleteOnRelease, 'ptr*', 0)
    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $Ret[0] Then
            Return SetError(1, $Ret[0], 0)
        EndIf
    EndIf
    Return $Ret[3]
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal

Func PNG_Data()
    $bPNG = '0x89504E470D0A1A0A0000000D4948445200000040000000400806000000AA6971DE0000088F49444154785EED9A5D6C1C5715C77F77667776D7EBCFC6F9B0DBB4CEB79BA64DA2B669044F80A0A10F20FAD60778A1EF3C202121C40320211EFA0A08090984A04520FA8052A4A83414A9140835C29094A4694B52FCEDC4F67AD7F6EECCDC7BD85E9199A947BB1BAF3711A2FB978EEEF1CCBCFCFFF33FE7DCBD1E3E94E8A28B2EBAE8A28B2EBAE8A28B2E1431840EE2877416CF7E9DCEE25B28800C09BCF8E28BCCCCCCA094A25DE47239F2F93C9FCC6450F500EC8A5251DE0C12865888DCCAEDFAD34743AA61959AA9B16508166284D19E519EFEF1D300A404D05AB3B8B86805D82E3E4A67F1F641B60D31C2EEC26E80B400AEEB522A953A26804F67B1B8C1F6202022948B655C5C343AED80F9F979D6D6D63A2280A6B3580B3B208011E636E6520E88303D3D8DD6BA2302089D85369D71C074651A0C0D7B40C704301D17A0333D408B6EEC00638C0D2BC0FF180C1D71800DE443E780B8078412823476C0FF7D0F3062C0DC05014C6B7150775F001B0D7B40100477D4010238D92CB991119C4201279723585CC454AB7687A8CB65F4FBF91D6C82A1848D1D602D62CC1D13C02916F1EAE473A3A3481892191800A5C018BC3D7BF06FDE245858C09F9B437C9F248C74CC0177670CCAA65C655C0A0F3C805B27BD7EF52A8EE7616A35EB84A04EBC363383725D8A0F1EC5D4AA5467667188A13B244068C2A653C09681E3385840DB629804F9DCBEDD14C60F6096ABAC4E4C10542A784343A84C1613F858019697C90D0E601C8D77640FA159239C5EEE58098811ACC3318D0508C3D0'
    $bPNG &= '8AD08932101BE00E16E97BF2344EB140EDCABFF15756E87D681C7F6111EFC05EDB1396CFBF4AEF9183542E5DA667F818B9FDA3640F8CB2FCFC39C2E53514101ADA87241CA04330CD0588C86F47040308D073F43EC29532B258A2FC87BF5981F3470EE1EC1C60D7179E0184EAFC34DEAE114A7FBF547F6612B22E2A97253B7E1FFE6B6FA2B6E3002182D10623A6A900363A2580D397C75443F4E206923554A716705C17B738404FDF108A0288A130360E4AA1CCFBCFCC53ACF9500E31EB359C42065DAEB6EF00D9B4113261CB26687B80886C4B040DF43CB28FDE138FD17FFC09AE3FF76D0AE3FB08E76EE2AFDDC01BD9C9C2D99F030A67A04030BD8093CFE2ED1E66EDAF6F72FF97BF4AF9E2055421CBEAF9C9F61C2089D40818D04637152072403DB6D508052097A1BA3A45AF7A0C6A2E7D1F3B4DF5DDB7A9ADCC53BE3A49E5F5B700E8FBC811B2F7ECA4F0F038BD8F3FCECAD9DF42CEA1B6368FEAEF05ADD1A61DF269018C695202BEEFDB701C27222D2291205BC11A90F706305E91E9F3E7F0770C31FBEAABD4A666F08E8FD1FFD009763FF939A6BFFB7D96AE4EE11D75092E5E67E9BD19BC5D3B997EED15C4F1D03A4F250808D6DB13408866BF8DAAAA826EEC806833947CFB22D2D669ABAAF80C3D781AC7CD53F126295D789D8DA5325A0CEE600F85FDF7B2F74BCF32F3939F619410CEDEA46F7C9CFE53A7291C3E8CE8809BD7CEA2B4462BB606054A94E583025182D0780C46C4D353C0AE5B16C2012AFF9820736888E09D398A0F3F4CE58F6F20C0CE238F22732BDCB8F24BBCBD230C9E3C81E3F430632628FDEE357A9F7884C55FBF80777084CAE41B38C660DAA841'
    $bPNG &= '85C292161389A145836E3D069325D0564F1020985D4697D7D1992A1B8BEF921D1BA66F788CDE632791C067ED9F97717C0FEFDE5D64FA0719387912BF34CDC6CA35425DC129ADE24FDD408CD9CA563876ACD81CBBEAA807B49C0249926D3B40001D04947F3FC18ECF9CB16F78C7D79EA23C31C97BDF790EA51CF2FBF68152D4AE5F4787213BCE7C82DE535F64E3CA65B20777B1FCD2CB84E50D1C20D06D3AC0247A80A6E5184CD6FFB6CA40B0A0F6D60C99CC509DEC188BE75E423255B45F265BDC813F3F8793CF432683C83ABE5E60E99573DCF3A9A7A85E7987EAE529300669E3C79012851113911723A0ED186C7A2062CB6013F15443BCDD1200D06B15FEF58D6FD2FFE953E40EDF4FAE38CAE0573ECEFAE465FB1B00113C3743E1D82134AB04EBCBCC3CFF3D4A67FF04A1A06EB9696B25103740010C88B6797A279820D7B4098A487283D4D209861812C2EACB130CB97D0C7FFEB3A830833AEA92191C242C95A8CDCE92DBB997ECE830B33FFA01A5737FC15483883C4068B6F6F615568068FE23804909909A02361256B779C221B73D1A37DFD5ABEBDCF8C56FA85EBC4661FC306EB187DAFC3C4A416E6C3FD56BD729FFF902954B970022F2B13BB96D24C92B51B108A66509C40200D15B4F88B4ED33C1D58B1729D703402045D689056CFF404462218C98B80C8C447F372A81D426283D155A23162D8DE41D95CA5BC212680989FB8075B45160887AC0964E855B934F3F232277EC585C90D68E9428523DA0E9FF054424792E987446720C26D724E99403ECFD66E225EF35242349E2184CCA3631A198A01215F149E61A7D5BC7E2366FB01B8C0488C836B27DFA5A33315A5C'
    $bPNG &= 'D75187BF052D51434BB9424CAA046C18D3BC0422A580E424483A2365F74DF51F89214AA16C6E6FB4229B768231483D005CDCC801F5886A5C8B8E1A1E108F3E2176B3247A804D9A3BA059FD270588886EBA1F5DB7E45D179BDB15480A982E014424CEB546D503C051E6831627DEE9C5237AD3D1B7D888DFBAB4DE07D835310293B3DFC6A67A4F8991C9646C3860C9479FC9A49D105F83E84D2B2C9BE89A84210059478358D1A3376C3028544C2C3EFD8D7220B9174090865F88D8A8136834DA225112751F3D9FCD666FAD3614A0367F270490288B342CE9D80161180950703500BEF641C03A0D874007A0C0514E74EC2D08963492DC6CD870707055FA0B114B647878D87EE494ECF2A43BBB7DA6A7A707CFF36C5E17CEE680BD5717803E4065B396AC8A9D1097431A91ED4D10247B0012041CDF1102500B6BD4740D6DB45DCBB532810908750842722F13BF71134F85E1C2304BCE123E7E7290C0E0E0A0D44958A209BBB7B527007886CEE285335820E9B37EA4C18F20A2EB51CF30C6E0873E2BBF5A517C68D145175D74D145175D74D145175DFC076163E2688EDEC0010000000049454E44AE426082'
    Return $bPNG
EndFunc

Further use $hImageList = _GUIImageList_Create(64,64,5) instead.

 

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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