Jump to content

Add image to image with GDI Plus


Recommended Posts

hello all, this is my code:

#include <GDIPlus.au3>

$image_bg = "bg.png"
$image_logo = "logo.png"
$image_out = "result.png"


 InmageInImage ($image_out, $image_bg, $image_logo, 20)
    
    
Func InmageInImage ($image_out, $image_bg, $image_logo, $Rotate = 0)
    _GDIPlus_Startup ()
    $hBitmap = _GDIPlus_BitmapCreateFromFile ($image_bg)
    $hBitmap1 = _GDIPlus_BitmapCreateFromFile ($image_logo)
    $iW = _GDIPlus_ImageGetWidth ($hBitmap1)
    $iH = _GDIPlus_ImageGetHeight ($hBitmap1)
    $iW2 = $iW / 2
    $iH2 = $iH / 2

    ; rotate
    $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hBitmap)
    $hMatrix = _GDIPlus_Matrixcreate ()
    _GDIPlus_MatrixTranslate ($hMatrix, $iW2, $iW2)
    _GDIPlus_MatrixRotate ($hMatrix, $Rotate) 
    _GDIPlus_GraphicsSetTransform ($hGraphic, $hMatrix)
    _GDIPlus_MatrixTranslate ($hMatrix, -$iW2, -$iW2)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hBitmap1, -$iW2, -$iH2) 
    _GDIPlus_ImageSaveToFile ($hBitmap, @ScriptDir & "\" & $image_out)
    ShellExecute (@ScriptDir & "\" & $image_out)
    ; dispose
    _GDIPlus_MatrixDispose ($hMatrix)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_BitmapDispose ($hBitmap)
    _GDIPlus_BitmapDispose ($hBitmap)
    _GDIPlus_Shutdown ()
EndFunc

This code can rotate Add image to image but can not customize image location logo.png in bg.png image, i've tried changing _GDIPlus_GraphicsDrawImage ($hGraphic, $hBitmap1, - $iW2, -$iH2 ) to _GDIPlus_GraphicsDrawImage ( $hGraphic, $hBitmap1, -$iW2 + 20, -$iH2 + 30), but the coordinates are wrong (but if set $ Rotate = 0, it works), any help?

Thank you

code.zip

Edited by nhockm4v
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...