Sign in to follow this  
Followers 0
Shanheavel

[Solved] Transparent color in BMP

6 posts in this topic

#1 ·  Posted (edited)

Hello,

I know BMP doesn't support transparency. But I've picture and I know color (0xFF00FF).

Posted Image

How can I change pink color to transparent using GUICtrlCreatePic?

Edited by Adrian777

Share this post


Link to post
Share on other sites



BUMP!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

$gui = GUICreate("", 144, 87, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xFF00FF)
$hLabel = GUICtrlCreateLabel("", 32, 9, 72, 64, -1, $GUI_WS_EX_PARENTDRAG)
$img = GUICtrlCreatePic(@ScriptDir & "\piclvq.bmp", 0, 0, 0, 0)
GUISetState(@SW_SHOW)

While 1
    Sleep ( 250 )
    If _IsPressed("1B") Then
        MsgBox(0,"_IsPressed", "Esc Key Pressed")
        ExitLoop
    EndIf
WEnd
Exit

The attached pic is a PNG. Convert it to a BMP before starting the script!

For a transparent PNG image you can use this code:

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


Opt("GuiOnEventMode", 1)

Local Const $STM_SETIMAGE = 0x0172
Local $hGUI, $Pic, $hImage, $hBmp, $iW, $iH

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("piclvq.png")
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hBitmap = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iW, $iH, $GDIP_PXF32ARGB)
$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

$hGUI = GUICreate("Test", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xFF00FF)
GUISetState()

$Pic = GUICtrlCreatePic("", 0, 0, 0, 0)
GUICtrlSendMsg($Pic, $STM_SETIMAGE, 0, $hBmp)
_WinAPI_DeleteObject($hBmp)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xFF00FF)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

GUICtrlSetOnEvent($Pic, "_Pic_Clicked")


Do
Until Not Sleep(1000)

Func _Pic_Clicked()
    MsgBox(0, "Test", "You clicked on the pic!")
EndFunc

Func _Quit()
    GUIDelete($hGUI)
    Exit
EndFunc

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

Share this post


Link to post
Share on other sites

This code is great! Thank you :x

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#Include <Constants.au3>
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173

$hForm = GUICreate('MyGUI', 400, 400)
$Pic = GUICtrlCreatePic('', 50, 50, 144, 87)
$hPic = GUICtrlGetHandle(-1)

$hDstDC = _WinAPI_CreateCompatibleDC(0)
$hBitmap = _WinAPI_CreateSolidBitmap(0, _WinAPI_GetSysColor($COLOR_3DFACE), 144, 87, 0)
$hDstSv = _WinAPI_SelectObject($hDstDC, $hBitmap)
$hSrcDC = _WinAPI_CreateCompatibleDC(0)
$hImg = _WinAPI_LoadImage(0, @ScriptDir & '\piclvq.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
$hSrcSv = _WinAPI_SelectObject($hSrcDC, $hImg)
_WinAPI_TransparentBlt($hDstDC, 0, 0, 144, 87, $hSrcDC, 0, 0, 144, 87, 0xFF00FF)

_WinAPI_SelectObject($hDstDC, $hDstSv)
_WinAPI_DeleteDC($hDstDC)
_WinAPI_SelectObject($hSrcDC, $hSrcSv)
_WinAPI_DeleteDC($hSrcDC)

_WinAPI_DeleteObject($hImg)

_WinAPI_DeleteObject(_SendMessage($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
$hPic = _SendMessage($hPic, $STM_GETIMAGE)
If $hPic <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
EndIf

GUISetState()

Do
Until GUIGetMsg() = -3

piclvq.bmp

Edited by Yashied

Share this post


Link to post
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
Sign in to follow this  
Followers 0