Sign in to follow this  
Followers 0
Biatu

GDI+ Multi-Colored gradient brush on lines?

5 posts in this topic

I have been having trouble with making lines using gdi+ that have 3 color gradients. is this even possible? and if so could I please get any pointers?

Thanks guys


What is what? What is what.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is 

_GDIPlus_LineBrushSetPresetBlend()  

what you looking for?

Br,

UEZ

Edited by UEZ
1 person likes this

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

#3 ·  Posted (edited)

Is 

_GDIPlus_LineBrushSetPresetBlend()  

what you looking for?

Br,

UEZ

Sort of, But how do I draw a line with that? the example shows a rect, but rect does not have a FromXY ToXY. And line draw uses a pen and not a brush.

Thanks again

Edit:

Basically what im trying to do is draw a thick line from point A to point B and have a gradient from the center of the line to the outer, and then fade into transparency.with the edge.

Like this but with multiple colors...neon-horizontal-line-gradient.jpg

Edited by Biatu

What is what? What is what.

Share this post


Link to post
Share on other sites

The link to the image is broken but you mean something like this here?
 

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

Example()

Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 300, $iBgColor = 0x303030 ;$iBgColor format RRGGBB

    Local $hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ;create a test GUI
    GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsClear($hGraphics, 0xFF303030)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)

    Local $iX1 = 20, $iX2 = 580, $iY1 = 200, $iY2 = 200
    Local $hBrush = _GDIPlus_LineBrushCreate($iX1, $iY1, $iX2, $iY2, 0, 0, 1) ;create line brush

    Local $aInterpolations[5][2] ;define the interpolated colors and positions
    $aInterpolations[0][0] = 4
    $aInterpolations[1][0] = 0x7FFF0000 ;Red
    $aInterpolations[1][1] = 0 ;0% from the left
    $aInterpolations[2][0] = 0xFF00FF00 ;Green
    $aInterpolations[2][1] = 0.40 ;To 40% from the left
    $aInterpolations[3][0] = 0xFF0000FF ;Blue
    $aInterpolations[3][1] = 0.60 ;To 60% from the left
    $aInterpolations[4][0] = 0x7FFFFF00 ;Yellow
    $aInterpolations[4][1] = 1 ;To 100% from the left

    _GDIPlus_LineBrushSetPresetBlend($hBrush, $aInterpolations) ;set the linear gradient brush colors and position

    Local $hPen = _GDIPlus_PenCreate2($hBrush, 8)

    _GDIPlus_GraphicsDrawLine($hGraphics, $iX1, $iY1, $iX2, $iY2, $hPen)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Br,

UEZ

1 person likes this

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

The link to the image is broken but you mean something like this here?

 

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

Example()

Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 300, $iBgColor = 0x303030 ;$iBgColor format RRGGBB

    Local $hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ;create a test GUI
    GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsClear($hGraphics, 0xFF303030)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)

    Local $iX1 = 20, $iX2 = 580, $iY1 = 200, $iY2 = 200
    Local $hBrush = _GDIPlus_LineBrushCreate($iX1, $iY1, $iX2, $iY2, 0, 0, 1) ;create line brush

    Local $aInterpolations[5][2] ;define the interpolated colors and positions
    $aInterpolations[0][0] = 4
    $aInterpolations[1][0] = 0x7FFF0000 ;Red
    $aInterpolations[1][1] = 0 ;0% from the left
    $aInterpolations[2][0] = 0xFF00FF00 ;Green
    $aInterpolations[2][1] = 0.40 ;To 40% from the left
    $aInterpolations[3][0] = 0xFF0000FF ;Blue
    $aInterpolations[3][1] = 0.60 ;To 60% from the left
    $aInterpolations[4][0] = 0x7FFFFF00 ;Yellow
    $aInterpolations[4][1] = 1 ;To 100% from the left

    _GDIPlus_LineBrushSetPresetBlend($hBrush, $aInterpolations) ;set the linear gradient brush colors and position

    Local $hPen = _GDIPlus_PenCreate2($hBrush, 8)

    _GDIPlus_GraphicsDrawLine($hGraphics, $iX1, $iY1, $iX2, $iY2, $hPen)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Br,

UEZ

Ah, yes thank you very much. didn't see PenCreate2. I will just need to adjust _GDIPlus_LineBrushCreate to make the grad vertical, which ive done experimenting with the Rect version in the help file.


What is what? What is what.

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