Jump to content

[Resolved] transparent gradient assistance


Recommended Posts

I've been looking around for a way to do this and I have a few theories I want to put on the table to see if I'm even aiming in the right direction.

I'm looking for a way to basically apply a circular transparency gradient to an image, say 800 x 800 as a background for a floating object.

I found:

...and have been scanning through the _alphablend.au3 file for a while now, but i'm not sure how i can merge that into what I am wanting to do.

So the first theory I had was maybe some layer design that would create multiple rings that were various levels of transparent, but that wouldn't really be a true gradient.

Second theory was to find some way to add the transparency into the image after it was loaded into the program / selected by the user.

Maybe I'm over thinking it or something, but just not really sure which direction to go with this still being pretty new to AutoIT.

As it stands all I have code wise is the loading of the image and setting the entire GUI form that it loads into set to a default transparency of about 100 - 125 so... essentially nothing. ;)

Thanks for whatever help and assistance is available in return for my request. :)

Edited by xeroTechnologiesLLC
Link to comment
Share on other sites

Do you mean something like that?

;coded by UEZ 2012
#include <ScreenCapture.au3>

_GDIPlus_Startup()
Global $iW = 600
Global $iH = 600

Global $hHBitmap = _ScreenCapture_Capture("", 0, 0, $iW, $iH)

Global $hGUI = GUICreate("Test", $iW, $iH)
GUISetState()

Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)

_GDIPlus_CircularGradient2Image($hGraphic, $hBitmap, -$iW / 2, -$iH / 2, $iW, $iH)

Do
Until GUIGetMsg() = -3

_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

Exit

Func _GDIPlus_CircularGradient2Image($hGraphic, $hBitmap, $iX, $iY, $iW, $iH, $iCenterColor = 0x10FFFFFF, $iBorderColor = 0xFF000000, $fCenterX = 0.5, $fCenterY = 0.5, $fFocus = 1, $fScale = 1)
    Local $hCtx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    DllCall($ghGDIPDll, "uint", "GdipAddPathEllipse", "handle", $hPath, "float", $iX, "float", $iY, "float", $iW * 2, "float", $iH * 2)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0)
    Local $hBrush = $aResult[2]
    Local $tPoint = DllStructCreate("float;float")
    DllStructSetData($tPoint, 1, $iW * $fCenterX)
    DllStructSetData($tPoint, 2, $iH * $fCenterY)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterPoint", "handle", $hBrush, "ptr", DllStructGetPtr($tPoint))
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterColor", "handle", $hBrush, "uint", $iCenterColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSigmaBlend", "handle", $hBrush, "float", $fFocus, "float", $fScale)
    Local $tColors = DllStructCreate("uint")
    DllStructSetData($tColors, 1, $iBorderColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush, "ptr", DllStructGetPtr($tColors), "int*", 1)
    _GDIPlus_GraphicsFillEllipse($hCtx, $iX, $iY, $iW * 2, $iH * 2, $hBrush)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCtx)
    Return 1
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

That'd do it. :)

If I understand the logic of the code correctly, I take the below and reference it to the GUICtrlCreatePic variable and it should do just what I'm needing? :D

Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
_GDIPlus_CircularGradient2Image($hGraphic, $hBitmap, -$iW / 2, -$iH / 2, $iW, $iH)

Once again you are awesome. ;)

There is so much on the GDI and API side of things I'm horribly foggy on, but I'm slowly starting to grasp it I think....hope... lol :D

Link to comment
Share on other sites

Sorry for the region mess - I section off a lot of my code to make it easier for my mind and eyes to see things.

But this is what I have so far....

_GDIPlus_Startup()

#region +++ GUI BKG
Global $hGui = GUICreate("RadBKG", 1024, 800, $MposL[0] - 512, $MposL[1] - 400, $WS_POPUP, $WS_EX_TOOLWINDOW)
$hPicBox = GUICtrlCreatePic("C:3planets.bmp", 0, 0, 1024, 800)

GUISetState(@SW_HIDE) ;there is another function assigned to hotkeys that shows the GUI
#endregion

#region +++ GRADIENT TRANSPARENCY
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hPicBox)

_GDIPlus_CircularGradient2Image($hGraphic, $hBitmap, $MposL[0] - 512, $MposL[1] - 400, 1024, 800)  ; i used $MposL[0] - 512, $MposL[1] - 400 thinking it would work based on the fact the $hGui loads off the mpos as well

#endregion

#region +++ WHILE LOOP
While 1
  Sleep(100)
WEnd
#endregion

Then referencing...

Func _GDIPlus_CircularGradient2Image($hGraphic, $hBitmap, $iX, $iY, $iWidth, $iHeight, $iCenterColor = 0x10FFFFFF, $iBorderColor = 0xFF000000, $fCenterX = 0.5, $fCenterY = 0.5, $fFocus = 1, $fScale = 1)
    Local $hCtx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    DllCall($ghGDIPDll, "uint", "GdipAddPathEllipse", "handle", $hPath, "float", $iX, "float", $iY, "float", $iWidth * 2, "float", $iHeight * 2)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0)
    Local $hBrush = $aResult[2]
    Local $tPoint = DllStructCreate("float;float")
    DllStructSetData($tPoint, 1, $iWidth * $fCenterX)
    DllStructSetData($tPoint, 2, $iHeight * $fCenterY)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterPoint", "handle", $hBrush, "ptr", DllStructGetPtr($tPoint))
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterColor", "handle", $hBrush, "uint", $iCenterColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSigmaBlend", "handle", $hBrush, "float", $fFocus, "float", $fScale)
    Local $tColors = DllStructCreate("uint")
    DllStructSetData($tColors, 1, $iBorderColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush, "ptr", DllStructGetPtr($tColors), "int*", 1)
    _GDIPlus_GraphicsFillEllipse($hCtx, $iX, $iY, $iWidth * 2, $iHeight * 2, $hBrush)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCtx)
    Return 1
EndFunc

The program loads just fine but the background image referenced in...

$hPicBox = GUICtrlCreatePic("C:3planets.bmp", 0, 0, 1024, 800)

...shows no change/transparency.

I will continue to do some research and weigh vs your example and see what I can figure out. Input is always appreciated.

And thank you again.

edit:corrected file type to bitmap - problem #1

Edited by xeroTechnologiesLLC
Link to comment
Share on other sites

What do you want to do exactly?

Are you trying to load an image, do a circular gradient to the image and display it in a picture control? This is more or less what I read from your code in post#4.

If this is what you are trying then it is the wrong way to do it. You cannot load an image to a picture control and manipulate it afterwards within the picture control.

You have to load an image, do the manipulation and send the manipulated image to the picture control. To do this you have to change the _GDIPlus_CircularGradient2Image() appropriately because it will send the manipulated image to a GDI+ graphic control.

If you need help let me know it.

Br,

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

Actually - I lied.

1 quick question.

When you're noting to load the image, are you referencing load the image into a GDI function of some sorts or something else?

I apologize. I'm not very familiar with this concept yet. :

Edit:

This is a general idea that I am following with not really knowing what I'm doing... LOL

Global $hBmp = _GDIPlus_BitmapCreateFromFile("c:fireSky.bmp")
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_GDIPlus_CircularGradient2Image($hGraphic, $hBitmap, $MposL[0] - 512, $MposL[1] - 400, 1024, 800)

Then in the GUI form:

Global $hPicBox = GUICtrlCreatePic($hBitmap, 0, 0, $bkgPicWidth, $bkgPicHeight)

And the function:

Func _GDIPlus_CircularGradient2Image($hGraphic, $hBitmap, $iX, $iY, $iWidth, $iHeight, $iCenterColor = 0x10FFFFFF, $iBorderColor = 0xFF000000, $fCenterX = 0.5, $fCenterY = 0.5, $fFocus = 1, $fScale = 1)
    Local $hCtx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    DllCall($ghGDIPDll, "uint", "GdipAddPathEllipse", "handle", $hPath, "float", $iX, "float", $iY, "float", $iWidth * 2, "float", $iHeight * 2)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0)
    Local $hBrush = $aResult[2]
    Local $tPoint = DllStructCreate("float;float")
    DllStructSetData($tPoint, 1, $iWidth * $fCenterX)
    DllStructSetData($tPoint, 2, $iHeight * $fCenterY)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterPoint", "handle", $hBrush, "ptr", DllStructGetPtr($tPoint))
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterColor", "handle", $hBrush, "uint", $iCenterColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSigmaBlend", "handle", $hBrush, "float", $fFocus, "float", $fScale)
    Local $tColors = DllStructCreate("uint")
    DllStructSetData($tColors, 1, $iBorderColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush, "ptr", DllStructGetPtr($tColors), "int*", 1)
    _GDIPlus_GraphicsFillEllipse($hCtx, $iX, $iY, $iWidth * 2, $iHeight * 2, $hBrush)
    _GDIPlus_GraphicsDrawImage($hPicBox, $hBitmap, 0, 0)
    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCtx)
    Return 1
EndFunc

Sorry if I am brutalizing your code, I honestly am not trying to. ><

Edited by xeroTechnologiesLLC
Link to comment
Share on other sites

Here the modified version to load an image, do a circular gradient to the image and display it in a picture control.

;coded by UEZ 2012
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>


_GDIPlus_Startup()

Global $hBitmap = _GDIPlus_BitmapCreateFromFile(StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUImsoobe.jpg"))

Global $iW = _GDIPlus_ImageGetWidth($hBitmap)
Global $iH = _GDIPlus_ImageGetHeight($hBitmap)

Global $hGUI = GUICreate("Test", $iW, $iH)
Global $idPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
_GDIPlus_CircularGradient2Image($idPic, $hBitmap, -$iW / 2, -$iH / 2, $iW, $iH)
GUISetState()

Do
Until GUIGetMsg() = -3

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()

Exit

;creates a circular gradient to an image and send it to a pic control
Func _GDIPlus_CircularGradient2Image($iPicControlID, $hBitmap, $iX, $iY, $iW, $iH, $iCenterColor = 0x10FFFFFF, $iBorderColor = 0xFF000000, $fCenterX = 0.5, $fCenterY = 0.5, $fFocus = 1, $fScale = 1)
    Local $hCtx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    DllCall($ghGDIPDll, "uint", "GdipAddPathEllipse", "handle", $hPath, "float", $iX, "float", $iY, "float", $iW * 2, "float", $iH * 2)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0)
    Local $hBrush = $aResult[2]
    Local $tPoint = DllStructCreate("float;float")
    DllStructSetData($tPoint, 1, $iW * $fCenterX)
    DllStructSetData($tPoint, 2, $iH * $fCenterY)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterPoint", "handle", $hBrush, "ptr", DllStructGetPtr($tPoint))
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientCenterColor", "handle", $hBrush, "uint", $iCenterColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSigmaBlend", "handle", $hBrush, "float", $fFocus, "float", $fScale)
    Local $tColors = DllStructCreate("uint")
    DllStructSetData($tColors, 1, $iBorderColor)
    DllCall($ghGDIPDll, "uint", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush, "ptr", DllStructGetPtr($tColors), "int*", 1)
    _GDIPlus_GraphicsFillEllipse($hCtx, $iX, $iY, $iW * 2, $iH * 2, $hBrush)
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iPicControlID, 0x0172, 0, $hHBitmap))
    _WinAPI_DeleteObject($hHBitmap)
    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCtx)
    Return 1
EndFunc

Br,

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

This works, so subject will be marked as resolved.

Unfortunately when I tied it into the program I was working on, it didn't visually turn out so well with the other aspects of the program. LOL

Oh well, this is going in the code archive because I know I will be using this later on again.

As always, UEZ your help, intellect and experience are very appreciated!

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...