Von Bild Ring ausschneiden (kein Kreis!)

  • Hallo ALLE!

    Seit gestern mittag stellt sich bei mir die frage wie ich einen "ring" aus einem rechteckigen .gif/.jpg ausschneiden kann.
    In der ShoutBox konnte auch niemand die frage beantworten ( UEZ war gerade nicht da xDD ).

    Mein jetztiges script ist das hier:

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("RingBild", 381, 342, 192, 124)
    $Slider1 = GUICtrlCreateSlider(8, 288, 353, 33)
    $Pic1 = GUICtrlCreatePic("C:\Dokumente und Einstellungen\Gamer\Desktop\Explodierender planet.jpg", 8, 8, 361, 273, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

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

    So! jetzt möchte ich aber nur einen kleinen ring (keinen kreis sondern ein ring!) von diesem bild haben (sollte ca. 15 pixel breit sein)

    Bild gibts hier:

    Spoiler anzeigen

    (sry qualitäät is ncht so gut aber egal!)


    Ist bestimmt was mit GDI+ und da bin ich nicht gerade der beste :D
    Wenn ihr's schafft dann echt respekt :D :D

    MfG
    Alizame

    Einmal editiert, zuletzt von Alizame (18. April 2010 um 09:55)

  • Hier ein 5 Minuten Skript:

    Spoiler anzeigen
    [autoit]


    #include <GDIplus.au3>
    Opt("GUIOnEventMode", 1)

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

    Local $width = 400
    Local $height = 300
    Local $hwnd = GUICreate("Make Donut by UEZ 2010 d-_-b", $width, $height, -1, -1)
    GUISetOnEvent(-3, "_Exit")
    GUISetState()

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

    _GDIPlus_StartUp()
    Local $hBild = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\akdmbg13jtj.jpg")

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

    Make_Donut($hBild, 150, 400)

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

    Do
    Until False * Not Sleep(100000)

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

    Func Make_Donut($hImage, $ir, $size)
    Local $iX = _GDIPlus_ImageGetWidth ($hImage)
    Local $iY = _GDIPlus_ImageGetHeight ($hImage)
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphics)
    Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $hPen = _GDIPlus_PenCreate(0xFF000000, $size / 8)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
    _GDIPlus_GraphicsClear($hBackbuffer)
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage, $iX / 2 - $size / 2, $iY / 2 - $size / 2, $size, $size)
    _GDIPlus_GraphicsFillEllipse($hBackbuffer, $iX / 2 - $ir / 2, $iY / 2 - $ir / 2, $ir, $ir, $hBrush)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $iX / 2 - $size / 2, $iY / 2 - $size / 2, $size, $size, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $width, $height)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    EndFunc

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

    Func _Exit()
    _GDIPlus_ImageDispose($hBild)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]

    Das Bild akdmbg13jtj.jpg sollte im Skript Verzeichnis sein!

    Das Drumherum kannst du ja selbst machen (Übung). ;)

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • In 2 Schritten!
    Erst einen kreis ausschneiden und aus dem Objekt nen kleineren Kreis ! :)

  • DANKE!
    werds mal testen jetzt!

    1ne sache noch!und zwar möchte ich es so machen das der "ring" unten anfängt und im uhrzeigersinn verläuft und man dann bestimmen kann von komplett bis fast kein "ring" (also brauchen wir jetzt einen slider)

    MfG
    Alizame

    Einmal editiert, zuletzt von Alizame (17. April 2010 um 17:38)

  • So, ein Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstants.au3>

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

    $iGUIWidth = 400
    $iGUIHeight = 400
    $GUIColorBG = 0xFF000000

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

    $iAngle = 1

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

    $hWnd = GUICreate("Test", $iGUIWidth, $iGUIHeight)
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGUIWidth, $iGUIHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    _GDIPlus_GraphicsClear($hGraphic, $GUIColorBG)

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

    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Test.png")
    $hTextureBrush = _GDIPlus_TextureCreate2($hImage, 0, 0, 300, 300)

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

    AdlibRegister("_Draw", 20)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    AdlibUnRegister()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BrushDispose($hTextureBrush)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    WEnd

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

    Func _Draw()
    $iAngle += 1
    _GDIPlus_GraphicsClear($hBuffer, $GUIColorBG)
    _GDIPlus_GraphicsFillPie($hBuffer, 50, 50, 100, 100, 90, $iAngle, $hTextureBrush)
    _GDIPlus_GraphicsFillEllipse($hBuffer, 83, 83, 36, 36)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iGUIWidth, $iGUIHeight)
    EndFunc

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

    ;Die Funktionen sind nicht von mir!!
    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_TextureCreate
    ; Description ...: Creates a TextureBrush object based on an image and a wrap mode
    ; Syntax.........: _GDIPlus_TextureCreate($hImage[, $iWrapMode = 0])
    ; Parameters ....: $hImage - Pointer to an Image object
    ; $iWrapMode - Wrap mode that specifies how repeated copies of an image are used to tile an area when it is
    ; +painted with the texture brush:
    ; |0 - Tiling without flipping
    ; |1 - Tiles are flipped horizontally as you move from one tile to the next in a row
    ; |2 - Tiles are flipped vertically as you move from one tile to the next in a column
    ; |3 - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
    ; |4 - No tiling takes place
    ; Return values .: Success - Pointer to a new TextureBrush object
    ; Failure - 0 and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: The size of the brush defaults to the size of the image, so the entire image is used by the brush
    ; After you are done with the object, call _GDIPlus_BrushDispose to release the object resources
    ; Related .......: _GDIPlus_BrushDispose
    ; Link ..........; @@MsdnLink@@ GdipCreateTexture
    ; Example .......; No
    ; ===============================================================================================================================
    Func _GDIPlus_TextureCreate($hImage, $iWrapMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hImage, "int", $iWrapMode, "int*", 0)

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

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[3]
    EndFunc ;==>_GDIPlus_TextureCreate

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_TextureCreate2
    ; Description ...: Creates a TextureBrush object based on an image, a wrap mode and a defining rectangle
    ; Syntax.........: _GDIPlus_TextureCreate2($hImage, $nX, $nY, $nWidth, $nHeight[, $iWrapMode = 0])
    ; Parameters ....: $hImage - Pointer to an Image object
    ; $nX - Leftmost coordinate of the image portion to be used by this brush
    ; $nY - Uppermost coordinate of the image portion to be used by this brush
    ; $nWidth - Width of the brush and width of the image portion to be used by the brush
    ; $nHeight - Height of the brush and height of the image portion to be used by the brush
    ; $iWrapMode - Wrap mode that specifies how repeated copies of an image are used to tile an area when it is
    ; +painted with the texture brush:
    ; |0 - Tiling without flipping
    ; |1 - Tiles are flipped horizontally as you move from one tile to the next in a row
    ; |2 - Tiles are flipped vertically as you move from one tile to the next in a column
    ; |3 - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
    ; |4 - No tiling takes place
    ; Return values .: Success - Pointer to a new TextureBrush object
    ; Failure - 0 and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: After you are done with the object, call _GDIPlus_BrushDispose to release the object resources
    ; Related .......: _GDIPlus_BrushDispose
    ; Link ..........; @@MsdnLink@@ GdipCreateTexture2
    ; Example .......; No
    ; ===============================================================================================================================
    Func _GDIPlus_TextureCreate2($hImage, $nX, $nY, $nWidth, $nHeight, $iWrapMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture2", "hwnd", $hImage, "int", $iWrapMode, "float", $nX, "float", $nY, "float", $nWidth, "float", $nHeight, "int*", 0)

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

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[7]
    EndFunc ;==>_GDIPlus_TextureCreate2

    [/autoit]


    Müsste genau das machen was du gesagt hast. :)
    Wofür ist das ganze? Vielleicht geht es auch einfacher. ;)

  • für alle die jetzt den endcode haben möchten:

    Spoiler anzeigen
    [autoit]


    ;sry solange der musikplayer wettbewerb läuft könnte mir das jeder klauen!!

    [/autoit]

    MfG
    Alizame

    Einmal editiert, zuletzt von Alizame (18. April 2010 um 10:15)