NassauSky Posted May 4 Share Posted May 4 (edited) I will be using some images similar to the one I have attached to this post, which isn't the clearest, so it would be nice to have a better rendering on the PC's Here is the slightly modified following code I'm using. Thanks @UEZ! What can I do to increase the clarity since the example image is very pixelated yet it shows up much clearer in other code? I'll provide another example if needed. BTW I left in a white slightly shaded oval in that image that you might not see until it's rendered using the code below. expandcollapse popup#include <WindowsConstants.au3> #include <WinAPISysWin.au3> #include <GDIPlus.au3> Opt("GUIOnEventMode", 1) Global Const $width = 600 Global Const $height = 600 _GDIPlus_Startup() Global $ghGDIPDll = DllOpen("gdiplus.dll") ; Open GDI+ DLL Local $IMAGE_PATH = @ScriptDir & "\TransparentImageOverlay.png" If Not FileExists($IMAGE_PATH) Then MsgBox(($MB_SYSTEMMODAL + $MB_ICONHAND), "", $IMAGE_PATH & " not found!", 30) Exit EndIf $g_hImage = _GDIPlus_ImageLoadFromFile($IMAGE_PATH) $hBG_Bitmap = $g_hImage Global $hWnd = GUICreate("GDI+: Example by UEZ 2010", $width, $height, -1, -1, 0, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW) GUISetOnEvent(-3, "_Exit") GUISetState() Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics) ; AI recommends a 4th param 32-bit ARGB bitmap to be higher res Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; Set up transparency Global $alpha = 255 ; Full opacity Global $tBlend = DllStructCreate($tagBLENDFUNCTION) Global $pBlend = DllStructGetPtr($tBlend) ; Declare $pBlend and get its pointer DllStructSetData($tBlend, "Alpha", $alpha) DllStructSetData($tBlend, "Format", 1) #Region Make GUI transparent $ScreenDc = _WinAPI_GetDC($hWnd) $GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) $dc = _WinAPI_CreateCompatibleDC($ScreenDc) _WinAPI_SelectObject($dc, $GDIBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $width) DllStructSetData($tSize, "Y", $height) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tPoint = DllStructCreate($tagPOINT) $pPoint = DllStructGetPtr($tPoint) DllStructSetData($tPoint, "X", 0) DllStructSetData($tPoint, "Y", 0) #EndRegion Global $hMatrix = _GDIPlus_MatrixCreate() Global $rot_mid_x = $width / 2 Global $rot_mid_y = $height / 2 _GDIPlus_MatrixTranslate($hMatrix, $rot_mid_x, $rot_mid_y) Local $iAngle = 10 While Sleep(50) _GDIPlus_GraphicsClear($hBackbuffer, 0xFF000000) ; Clear with opaque black color _GDIPlus_MatrixRotate($hMatrix, $iAngle, "False") _GDIPlus_GraphicsSetTransform($hBackbuffer, $hMatrix) _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBG_Bitmap, -$rot_mid_x / 2, -$rot_mid_y / 2, $width / 2, $height / 2) ;_GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBG_Bitmap, -$aFittingRect[0]/2, -$aFittingRect[1]/2, $aFittingRect[0], $aFittingRect[1]) $GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_SelectObject($dc, $GDIBitmap) _WinAPI_UpdateLayeredWindow($hWnd, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 1) _WinAPI_DeleteObject($GDIBitmap) WEnd Func _Exit() _WinAPI_DeleteDC($dc) _WinAPI_ReleaseDC($hWnd, $ScreenDc) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() DllClose($ghGDIPDll) ; Close GDI+ DLL Exit EndFunc Edited May 4 by NassauSky Link to comment Share on other sites More sharing options...
Solution UEZ Posted May 5 Solution Share Posted May 5 (edited) The problem is that the image is semi-transparent and thus it looks good on white background. If you change the bg to black the result is the same as in your code. I don't have an idee yet how to display it with white bg but in a transparent GUI. Edit: If your bg is light then you can use: While Sleep(10) _GDIPlus_GraphicsClear($hBackbuffer, 0) ; Clear with opaque black color _GDIPlus_MatrixRotate($hMatrix, $iAngle, "False") _GDIPlus_GraphicsSetTransform($hBackbuffer, $hMatrix) _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBG_Bitmap, -$rot_mid_x / 2, -$rot_mid_y / 2, $width / 2, $height / 2) $GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap, 0xFFFFFFFF) _WinAPI_SelectObject($dc, $GDIBitmap) _WinAPI_UpdateLayeredWindow($hWnd, $ScreenDc, 0, $pSize, $dc, $pSource, 0xFFFFFFFF, $pBlend, 1) _WinAPI_DeleteObject($GDIBitmap) WEnd which will add white as a bg color. Edited May 5 by UEZ Parsix and NassauSky 1 1 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 More sharing options...
NassauSky Posted May 5 Author Share Posted May 5 (edited) Thanks @UEZ that's a good thing to know! That will do the trick for certain images that will take too long to modify. If anyone else ever finds an idea how to work with semitransparent PNG files to display with the semi transparent effect I'd love to know. 🙂 Edited May 5 by NassauSky Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now