nend Posted January 6, 2010 Share Posted January 6, 2010 #include <GDIPlus.au3> _GDIPlus_Startup() $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\in.png") $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1) $matrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($matrix, 45) _GDIPlus_GraphicsSetTransform($hGraphic, $matrix) _GDIPlus_ImageSaveToFile($hImage1, @ScriptDir & "\out.png") _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage1) _GDIPlus_ShutDown ()So close but I just can get it right. I just want to load a small png file rotate it 45 degrees and save it. Is there a GDI guru how can help me? Link to comment Share on other sites More sharing options...
wraithdu Posted January 6, 2010 Share Posted January 6, 2010 (edited) You've created your graphics object and set the transform, but you haven't actually drawn anything to it. You'll need to use GraphicsDrawImage or similar. ... $matrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($matrix, 45) _GDIPlus_GraphicsSetTransform($hGraphic, $matrix) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage1, 10, 10) _GDIPlus_ImageSaveToFile($hImage1, @ScriptDir & "\out.png") _GDIPlus_MatrixDispose($matrix) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage1) _GDIPlus_ShutDown () Edited January 6, 2010 by wraithdu Link to comment Share on other sites More sharing options...
nend Posted January 6, 2010 Author Share Posted January 6, 2010 (edited) When I use this code I get two of the same images in 1 images. 1 the normal png 2 the rotated png I want it to rotate but not merged 2 of the same images. Have you got a other idea how to do this? You've created your graphics object and set the transform, but you haven't actually drawn anything to it. You'll need to use GraphicsDrawImage or similar. ... $matrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($matrix, 45) _GDIPlus_GraphicsSetTransform($hGraphic, $matrix) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage1, 10, 10) _GDIPlus_ImageSaveToFile($hImage1, @ScriptDir & "\out.png") _GDIPlus_MatrixDispose($matrix) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage1) _GDIPlus_ShutDown () Edited January 6, 2010 by nend Link to comment Share on other sites More sharing options...
wraithdu Posted January 6, 2010 Share Posted January 6, 2010 The example should have been enough to get you there. You need to create a new bitmap to draw your new image. #include <GDIPlus.au3> _GDIPlus_Startup() $hImage1 = _GDIPlus_ImageLoadFromFile($img) $hGraphic1 = _GDIPlus_ImageGetGraphicsContext($hImage1) $hImage2 = _GDIPlus_BitmapCreateFromGraphics(_GDIPlus_ImageGetWidth($hImage1), _GDIPlus_ImageGetHeight($hImage1), $hGraphic1) $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hImage2) $matrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($matrix, 45) _GDIPlus_GraphicsSetTransform($hGraphic2, $matrix) _GDIPlus_GraphicsDrawImage($hGraphic2, $hImage1, 0, 0) _GDIPlus_ImageSaveToFile($hImage2, @ScriptDir & "\out.png") _GDIPlus_MatrixDispose($matrix) _GDIPlus_GraphicsDispose($hGraphic1) _GDIPlus_GraphicsDispose($hGraphic2) _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_ShutDown () You can play with position and size yourself. Link to comment Share on other sites More sharing options...
nend Posted January 6, 2010 Author Share Posted January 6, 2010 Perfect , thanks for your help!! The example should have been enough to get you there. You need to create a new bitmap to draw your new image. #include <GDIPlus.au3> _GDIPlus_Startup() $hImage1 = _GDIPlus_ImageLoadFromFile($img) $hGraphic1 = _GDIPlus_ImageGetGraphicsContext($hImage1) $hImage2 = _GDIPlus_BitmapCreateFromGraphics(_GDIPlus_ImageGetWidth($hImage1), _GDIPlus_ImageGetHeight($hImage1), $hGraphic1) $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hImage2) $matrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($matrix, 45) _GDIPlus_GraphicsSetTransform($hGraphic2, $matrix) _GDIPlus_GraphicsDrawImage($hGraphic2, $hImage1, 0, 0) _GDIPlus_ImageSaveToFile($hImage2, @ScriptDir & "\out.png") _GDIPlus_MatrixDispose($matrix) _GDIPlus_GraphicsDispose($hGraphic1) _GDIPlus_GraphicsDispose($hGraphic2) _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_ShutDown () You can play with position and size yourself. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now