Jump to content
Sign in to follow this  

[SOLVED] GDI+ rounded corners on a image

Recommended Posts


Hi Guys,

Is it possible with GDI+ to make transparent rounded corners on a image?
I found a few examples but that output a GUI with rounded corners but I couldn't find a example of a image.

This is what I have so far.

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


Local Const $iWidth = 400, $iHeight = 200

Local $hGUI = GUICreate("", $iWidth, $iHeight)


Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
$hBrush = _GDIPlus_LineBrushCreate(17, 110, 320, 110, 0xFF000000, 0xFFFFFFFF , 1)
_GDIPlus_GraphicsFillRect($hGraphics, 20, 20, 297, 109, $hBrush)



Thanks for the help!

Edited by nend

Share this post

Link to post
Share on other sites

Here we go:

#include <GDIPlus.au3>

Global $sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.bmp;*.png;*.gif)")
If @error Then Exit MsgBox(16, "Error", "You must select an image!", 20)

Global Const $hImg = _GDIPlus_ImageLoadFromFile($sFile)
Global Const $hBmp = _GDIPlus_BitmapCreateRoundedCornerFromBitmap($hImg)
_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\TestImg.png")
ShellExecute(@ScriptDir & "\TestImg.png")

Func _GDIPlus_BitmapCreateRoundedCornerFromBitmap($hImage, $fRadiusCorner = -1, $bBorder = False, $iBorderColor = 0xE0FFFFFF, $iBorderSize = 1) ;coded by UEZ buid 2017-04-17
    Local $aDim = _GDIPlus_ImageGetDimension($hImage)
    If @error Then Return SetError(1, 0, 0)

    Local Const $iW = $aDim[0], $iH = $aDim[1]
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4)
    _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 4)
    _GDIPlus_GraphicsSetCompositingQuality($hGfx, 2)

    Local Const $hTexture = _GDIPlus_TextureCreate($hImage)
    Local Const $hPath = _GDIPlus_PathCreate()

    If $fRadiusCorner = -1 Then
        $fRadiusCorner = (($iW + $iH) / 2) * 0.1

    _GDIPlus_PathAddArc($hPath, $iW - ($fRadiusCorner * 2), 0, $fRadiusCorner * 2, $fRadiusCorner * 2, 270, 90)
    _GDIPlus_PathAddArc($hPath, $iW - ($fRadiusCorner * 2), $iH - ($fRadiusCorner * 2), $fRadiusCorner * 2, $fRadiusCorner * 2, 0, 90)
    _GDIPlus_PathAddArc($hPath, 0, $iH - ($fRadiusCorner * 2), $fRadiusCorner * 2, $fRadiusCorner * 2, 90, 90)
    _GDIPlus_PathAddArc($hPath, 0, 0, $fRadiusCorner * 2, $fRadiusCorner * 2, 180, 90)

    _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hTexture)
    If $bBorder Then
        Local Const $hPen = _GDIPlus_PenCreate($iBorderColor, $iBorderSize)
        _GDIPlus_PenSetLineJoin($hPen, 2)
        _GDIPlus_PenSetAlignment($hPen, 1)
        _GDIPlus_GraphicsDrawPath($hGfx, $hPath, $hPen)


    Return $hBitmap
EndFunc   ;==>_GDIPlus_BitmapCreateRoundedCornerFromBitmap


Edited by UEZ
added border functionality
  • Like 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post

Link to post
Share on other sites

Only thing I can say woooh, great job.

Realy thanks for GDI+ expert knowledge

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