abgerundetes rechteck GDI+

  • Hi Leute kann mir bitte jemand erklären wie ich ein abgerundetes Rechteck mit Gdi+ erstellen kann am
    besten mit Border. Ich kann das ganze zwar auch per Image lösen doch das gefällt mir nicht so.

    bisher habe ich das: sieht ein bisschen albern aus :D

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $x=100,$y=10,$width = 100,$height = 100 ,$radius = 20

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hPen = _GDIPlus_PenCreate(0xFF4f6793,1,2)
    _GDIPlus_GraphicsDrawLine($hGraphic,$x + $radius,$y,$x + $width -$radius,$y,$hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic,$x + $width - $radius, $y, $radius,$radius, 270, 90,$hPen)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawLine($hGraphic,$x + $width, $y + $radius, $x + $width,$y + $height - $radius,$hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic,$x + $width - $radius, $y + $height - $radius,$radius, $radius, 0, 90,$hPen)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawLine($hGraphic,$x + $width - $radius, $y + $height,$x + $radius, $y + $height,$hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic,$x, $y + $height - $radius, $radius,$radius, 90, 90,$hPen)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawLine($hGraphic,$x, $y + $height - $radius, $x, $y + $radius,$hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic,$x, $y, $radius, $radius, 180, 90,$hPen)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()

    [/autoit]

    und das ist die lösung per image: geht zwar auch super aber will ich trozdem nicht ?(

    Spoiler anzeigen
    [autoit]

    Func _bitmap_stretch($pic,$nw,$nh)
    ;by Rodney_le_lude
    Local $strech_pointer[3],$gbitmap,$context,$hgraphic
    Local $bitmap = _GDIPlus_BitmapCreateFromFile($pic)
    If @error Then Return SetError(1)
    Local $width = _GDIPlus_ImageGetWidth($bitmap)
    Local $height = _GDIPlus_ImageGetHeight($bitmap)
    If $nw < $width And $nh < $height Then
    $bitmap = _bitmap_reduce($bitmap,$nw,$nh)
    Return $bitmap
    ElseIf $nw < $width And $nh >= $height Then
    $bitmap = _bitmap_reduce($bitmap,$nw,-1)
    ElseIf $nw >= $width And $nh < $height Then
    $bitmap = _bitmap_reduce($bitmap,-1,$nh)
    ElseIf $nw = $width And $nh = $height Then
    Return $bitmap
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $width = _GDIPlus_ImageGetWidth($bitmap)
    $height = _GDIPlus_ImageGetHeight($bitmap)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hgraphic = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
    $gbitmap = _GDIPlus_BitmapCreateFromGraphics($nw,$height,$hgraphic)
    $context = _GDIPlus_ImageGetGraphicsContext($gbitmap)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $strech_pointer[0] = _GDIPlus_BitmapCloneArea($bitmap,0,0,$width/2,$height,$GDIP_PXF32ARGB)
    $strech_pointer[1] = _GDIPlus_BitmapCloneArea($bitmap,$width/2,0,1,$height,$GDIP_PXF32ARGB)
    $strech_pointer[2] = _GDIPlus_BitmapCloneArea($bitmap,$width/2,0,$width/2,$height,$GDIP_PXF32ARGB)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRect($context,$strech_pointer[0],0,0,$width/2,$height)
    _GDIPlus_GraphicsDrawImageRect($context,$strech_pointer[2],$nw-$width/2,0,$width/2,$height)
    _GDIPlus_BitmapDispose($strech_pointer[0])
    _GDIPlus_BitmapDispose($strech_pointer[2])

    [/autoit] [autoit][/autoit] [autoit]

    For $i = $width/2 To $nw - $width/2 -1
    _GDIPlus_GraphicsDrawImageRect($context,$strech_pointer[1],$i,0,1,$height)
    Next
    _GDIPlus_BitmapDispose($strech_pointer[1])

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $strech_pointer[0] = _GDIPlus_BitmapCloneArea($gbitmap,0,0,$nw,$height/2,$GDIP_PXF32ARGB)
    $strech_pointer[1] = _GDIPlus_BitmapCloneArea($gbitmap,0,$height/2,$nw,1,$GDIP_PXF32ARGB)
    $strech_pointer[2] = _GDIPlus_BitmapCloneArea($gbitmap,0,$height/2,$nw,$height/2,$GDIP_PXF32ARGB)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDispose($context)
    _GDIPlus_BitmapDispose($gbitmap)

    [/autoit] [autoit][/autoit] [autoit]

    $gbitmap = _GDIPlus_BitmapCreateFromGraphics($nw,$nh,$hgraphic)
    $context = _GDIPlus_ImageGetGraphicsContext($gbitmap)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRect($context,$strech_pointer[0],0,0,$nw,$height/2)
    _GDIPlus_GraphicsDrawImageRect($context,$strech_pointer[2],0,$nh-$height/2,$nw,$height/2)
    _GDIPlus_BitmapDispose($strech_pointer[0])
    _GDIPlus_BitmapDispose($strech_pointer[2])

    [/autoit] [autoit][/autoit] [autoit]

    For $i = $height/2 To $nh - $height/2 -1
    _GDIPlus_GraphicsDrawImageRect($context,$strech_pointer[1],0,$i,$nw,1)
    Next
    _GDIPlus_BitmapDispose($strech_pointer[1])

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDispose($context)
    _GDIPlus_GraphicsDispose($hgraphic)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_BitmapDispose($bitmap)
    Return $gbitmap

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _bitmap_reduce($bitmap,$width = -1,$height = -1)
    ;by Rodney_le_lude
    If $width = -1 And $height = -1 Then Return $bitmap
    Local $hgraphic,$hbitmap,$context
    If $width = -1 Then $width = _GDIPlus_ImageGetWidth($bitmap)
    If $height = -1 Then $height = _GDIPlus_ImageGetHeight($bitmap)

    [/autoit] [autoit][/autoit] [autoit]

    $hgraphic = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
    $hbitmap = _GDIPlus_BitmapCreateFromGraphics($width,$height,$hgraphic)
    $context = _GDIPlus_ImageGetGraphicsContext($hbitmap)
    _GDIPlus_GraphicsDrawImageRect($context,$bitmap,0,0,$width,$height)
    _GDIPlus_GraphicsDispose($context)
    _GDIPlus_GraphicsDispose($hgraphic)
    _GDIPlus_BitmapDispose($bitmap)
    Return $hbitmap
    EndFunc

    [/autoit]

    http://img16.imageshack.us/i/35323219.png/

    Einmal editiert, zuletzt von Rodny_le_lude (9. Juli 2012 um 20:15)