Jump to content
HurpaDerp

DrawThemeBackground Bitmap Alpha

Recommended Posts

HurpaDerp

Im trying to create a script to extract control backgrounds for custom skinning, however the alpha background parts are turning black.

Can anyone point me in the right direction please?

#NoTrayIcon
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>
#include <WinAPITheme.au3>

Local $hGUI = GUICreate("ThemeData")
_GDIPlus_Startup()

Local $hTheme = _WinAPI_OpenThemeData($hGUI, 'Button')
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(50, 50, $GDIP_PXF32PARGB)
Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hGfx, 0x00)
Local $hDC = _GDIPlus_GraphicsGetDC($hGfx)

Local $tRect = _WinAPI_CreateRectEx(5, 5, 45, 45)
_WinAPI_DrawThemeBackground($hTheme, 2, 5, $hDC, $tRect); Checked Radiobutton


; Cleanup
_GDIPlus_GraphicsReleaseDC($hGfx, $hDC)
_GDIPlus_GraphicsDispose($hGfx)
_WinAPI_CloseThemeData($hTheme)

_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Image.png")
_GDIPlus_BitmapDispose($hBitmap)

GUIDelete()

 

Share this post


Link to post
Share on other sites
InunoTaishou

Are you sure it's turning black or does it just look black because that's how windows 10 shows transparency for icons in a folder?

I ran your script then opened the file in photoshop and the background is 100% transparent with just the radio button showing up.

Share this post


Link to post
Share on other sites
HurpaDerp

Yes its definetly turning black. The radio button shouldn't have a black "border", you might have to zoom in a bit to see it.

Its because its pre multiplying the alpha at some point, or it's drawing on a black background then combining onto the transparent one. I'm just not sure how to get it to draw directly onto the alpha bitmap.

Share this post


Link to post
Share on other sites
HurpaDerp

Nevermind, I managed to fix it.

#NoTrayIcon
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>
#include <WinAPISys.au3>
#include <WinAPITheme.au3>

Local $hTheme = _WinAPI_OpenThemeData(_WinAPI_GetDesktopWindow(), "Button")
Local $hDC = _WinAPI_CreateCompatibleDC(0)

Local $tBITMAPINFO = __CreateBitmapInfo(50, 50)
Local $pBits
Local $hBmp = _WinAPI_CreateDIBSection(0, $tBITMAPINFO, $DIB_RGB_COLORS, $pBits)
Local $hSel = _WinAPI_SelectObject($hDC, $hBmp)

Local $tRect = _WinAPI_CreateRectEx(0, 0, 50, 50)
_WinAPI_DrawThemeBackground($hTheme, 2, 5, $hDC, $tRect)
_WinAPI_CloseThemeData($hTheme)

_GDIPlus_Startup()
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(50, 50, $GDIP_PXF32ARGB, 50*4, $pBits)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Image.png")
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()

_WinAPI_SelectObject($hDC, $hSel)
_WinAPI_DeleteObject($hBmp)
_WinAPI_DeleteDC($hDC)

Func __CreateBitmapInfo($iWidth, $iHeight)
    Local $tBITMAPINFO = DllStructCreate($tagBITMAPINFOHEADER & ";dword biRGBQuad")
    DllStructSetData($tBITMAPINFO, 'biWidth', $iWidth)
    DllStructSetData($tBITMAPINFO, 'biHeight', -$iHeight)
    DllStructSetData($tBITMAPINFO, 'biPlanes', 1)
    DllStructSetData($tBITMAPINFO, 'biBitCount', 32)
    DllStructSetData($tBITMAPINFO, 'biCompression', 0)
    DllStructSetData($tBITMAPINFO, 'biSizeImage', 0)
    DllStructSetData($tBITMAPINFO, 'biSize', DllStructGetSize($tBITMAPINFO) - 4)

    Return $tBITMAPINFO
EndFunc     ;==>__CreateBitmapInfo

 

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.