Gdi+ Clone/Save

  • Guten Morgen!
    Ich poste einfach mal, weil ich eine totale niete in gdi+ bin und zu faul bin um projekte wie autoitoerids durchzuschauen...
    Wie kann ich ein Pic nehmen, dann clonen und unter das ursprungsbild tun und dann wieder speichern?

    Clonen und Speichern ist eigendlich kla (_GDIPlus_BitmapCloneArea + _GDIPlus_ImageSaveToFile) .. trotzdem hab ich den dreh noch nich raus :thumbdown:

    Naja sollte für die Gdi-Experten doch hoffentlich nicht schwer sein!

    -Chaos

    Einmal editiert, zuletzt von ChaosKeks (30. Juni 2009 um 20:47)

  • Guten Morgen!
    Ich poste einfach mal, weil ich eine totale niete in gdi+ bin und zu faul bin um projekte wie autoitoerids durchzuschauen...
    Wie kann ich ein Pic nehmen, dann clonen und unter das ursprungsbild tun und dann wieder speichern?

    Clonen und Speichern ist eigendlich kla (_GDIPlus_BitmapCloneArea + _GDIPlus_ImageSaveToFile) .. trotzdem hab ich den dreh noch nich raus :thumbdown:

    Naja sollte für die Gdi-Experten doch hoffentlich nicht schwer sein!

    -Chaos

    Moin,

    in AUTOITEROIDS wird du nicht weiter kommen, denn da werden "nur" rudimäntere GDI+ Befehle benutzt! ;)

    Wenn ich dich richtig verstanden habe, willst du ein Bild laden und es clonen, so dass das Bild unter dem Original Bild liegt.

    Schaue doch einfach mal unter http://www.autoitscript.com/forum/index.php?showtopic=87200 das Beispiel #07 Visualization: Analog Meter dir genauer an. Ich lade das Bild und clone es auf die rechte Seite!

    Zum Speichern kannst du den Befehl _GDIPlus_ImageSaveToFile($Bitmap, @ScriptDir & "\Bild.jpg") benutzen!

    Ich hoffe, dass ich dir weiter helfen konnte!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Habs hingegrigt.

    Hier:

    Spoiler anzeigen
    [autoit]

    #include <GDIplus.au3>
    #Include <ScreenCapture.au3>

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

    _ClonePicDown(@DesktopDir&"\Bild2Druck.JPG", @DesktopDir&"\test.jpg")

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

    Func _ClonePicDown($PfadZuBild,$PfadNeuerName)
    ; Greek
    _GDIPlus_Startup()
    $hImg1 = _GDIPlus_ImageLoadFromFile($PfadZuBild)
    $H=_GDIPlus_ImageGetHeight($hImg1)
    $W=_GDIPlus_ImageGetWidth($hImg1)
    $hGDIBitmap = _ScreenCapture_Capture("",0,0,$W,$H*2)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hGDIBitmap)
    _WinAPI_DeleteObject($hGDIBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    $ImageAttributes = _GDIPlus_ImageAttributesCreate()

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

    _DrawImage($hGraphic, $hImg1, 0,0,$ImageAttributes)
    _DrawImage($hGraphic, $hImg1, 0,$H,$ImageAttributes)

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

    _GDIPlus_ImageSaveToFile($hBitmap, $PfadNeuerName)

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

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImg1)
    _GDIPlus_BitmapDispose($hBitmap)
    $x2 = _GDIPlus_ImageAttributesDispose($ImageAttributes)
    _GDIPlus_Shutdown()
    EndFunc

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

    Func _DrawImage($hGraphics, $hImage, $X, $Y, $pImageAttributes)
    ; Prog@ndy
    Local $H = _GDIPlus_ImageGetHeight($hImage)
    Local $W = _GDIPlus_ImageGetWidth($hImage)
    Local $Result = _GDIPlus_GraphicsDrawImageRectRectAttr($hGraphics, $hImage, 0, 0, $W, $H, $X, $Y, $W, $H, 2, $pImageAttributes)
    Return SetError(@error,0,$Result)
    EndFunc

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

    Func _GDIPlus_GraphicsDrawImageRectRectAttr($hGraphics, $hImage, $iSrcX, $iSrcY, $iSrcWidth, $iSrcHeight, $iDstX, $iDstY, $iDstWidth, $iDstHeight, $iUnit = 2, $pImageAttributes=0)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "ptr", $hGraphics, "ptr", $hImage, "int", $iDstX, "int", _
    $iDstY, "int", $iDstWidth, "int", $iDstHeight, "int", $iSrcX, "int", $iSrcY, "int", $iSrcWidth, "int", _
    $iSrcHeight, "int", $iUnit, "ptr", $pImageAttributes, "ptr", 0, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
    EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectAttr

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

    Func _GDIPlus_ImageAttributesCreate()
    ; Prog@ndy
    Local $aResult = DllCall($ghGDIpDLL, "int", "GdipCreateImageAttributes", "ptr*", 0)
    If @error Then Return SetError(1,@error,0)
    Return SetError($aResult[0],0,$aResult[1])
    EndFunc

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

    Func _GDIPlus_ImageAttributesDispose($pImageAttributes)
    ; Prog@ndy
    Local $aResult = DllCall($ghGDIpDLL, "int", "GdipDisposeImageAttributes", "ptr", $pImageAttributes)
    If @error Then Return SetError(1,@error,0)
    Return SetError($aResult[0],0,$aResult[0]=0)
    EndFunc

    [/autoit]

    Edit:
    Hab mal meins verbessert, ist jetzt viel schneller ( von 128 ms auf 62 ms ).

    Einmal editiert, zuletzt von Greek (21. Juni 2009 um 20:31)

  • Viele Wege führen nach Rom, hier ein weiterer Weg:

    Spoiler anzeigen


    #include <GDIplus.au3>
    _GDIPlus_Startup()
    Global $bitmap_from_file = _GDIPlus_BitmapCreateFromFile("c:\windows\System32\oobe\info\background_wc.png")
    Global Const $iX = _GDIPlus_ImageGetWidth($bitmap_from_file)
    Global Const $iY = _GDIPlus_ImageGetHeight($bitmap_from_file)
    Global Const $width = $iX
    Global Const $height = 2 * $iY
    Global $hwnd = GUICreate("", $width, $height)
    Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
    Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
    Global $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    _GDIPlus_GraphicsDrawImage($backbuffer, $bitmap_from_file, 0, 0)
    _GDIPlus_GraphicsDrawImage($backbuffer, $bitmap_from_file, 0, $iY)
    GUISetState()

    Do
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    Until GUIGetMsg() = -3 * Sleep(30)

    _GDIPlus_ImageSaveToFile($bitmap, @ScriptDir & "\Test.bmp")
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_Shutdown()

    Exit

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (20. Juni 2009 um 18:49)

  • Hallo sry hab mich ne ewigkeit nicht mehr gemeldet.. mich hat die sommergrippe ganz schön erwischt :(
    Bin nur eben on gekommen um vielen dank zu sagen!
    Greek und UEZ, ihr habt mir sehr geholfen =]

    Cu hoffentlich bald..