Sign in to follow this  
Followers 0
MatthiasG

Transparent Pictures

3 posts in this topic

Hello there!

I tried to a transparent picture together with another.

My Background was the following:

post-51859-12521625165091_thumb.jpg

And the icon this one here:

test.ico

But instead of getting a new picture, I got this one:

post-51859-12521625400122_thumb.jpg

I tried also to make it with GDI+, but the result wasn't as good as I expected:

post-51859-12521626571792_thumb.png

As you can see, you can count the pixels.

How can I make this nicer?

Have a nice day,

Matthias

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this, but there is one problem - it only works with icons that have the Alpha channel.

#Include <WinAPIEx.au3>

$hForm = GUICreate('MyGUI', 178, 192)
GUICtrlCreatePic('index.jpeg', 0, 0, 178, 192)
$Icon = GUICtrlCreatePic('', 65, 60, 48, 48) ; (!)
;_SetIconAlpha($Icon, @SystemDir & '\shell32.dll', 130, 48, 48)
_SetIconAlpha($Icon, 'test.ico', 0, 48, 48)
GUISetState()

Do
Until GUIGetMsg() = -3

Func _SetIconAlpha($hWnd, $sIcon, $iIndex, $iWidth, $iHeight)

    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If $hWnd = 0 Then
            Return SetError(1, 0, 0)
        EndIf
    EndIf

    Local $hIcon = _WinAPI_ShellExtractIcons($sIcon, $iIndex, $iWidth, $iHeight)

    If $hIcon = 0 Then
        Return SetError(1, 0, 0)
    EndIf

    Local $hBitmap, $hObj, $hDC, $hMem, $hSv

    $hDC = _WinAPI_GetDC($hWnd)
    $hMem = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    $hSv = _WinAPI_SelectObject($hMem, $hBitmap)
    _WinAPI_DrawIconEx($hMem, 0, 0, $hIcon, $iWidth, $iHeight, 0, 0, 2)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMem, $hSv)
    _WinAPI_DeleteDC($hMem)
    _WinAPI_DestroyIcon($hIcon)
    _WinAPI_DeleteObject(_SendMessage($hWnd, 0x0172, 0, 0))
    _SendMessage($hWnd, 0x0172, 0, $hBitmap)
    $hObj = _SendMessage($hWnd, 0x0173)
    If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
    Return 1
EndFunc   ;==>_SetIconAlpha

WinAPIEx.au3

If you save your icon as a PNG image, you can use the Icons.au3 library.

#Include <Icons.au3>

$hForm = GUICreate('MyGUI', 178, 192)
GUICtrlCreatePic('index.jpeg', 0, 0, 178, 192)
$Pic = GUICtrlCreatePic('', 65, 60, 48, 48)
_SetImage($Pic, 'test.png')
GUISetState()

Do
Until GUIGetMsg() = -3

Icons.au3

Edited by Yashied

Share this post


Link to post
Share on other sites

Thanks a lot, it works! :D

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