Jump to content
MrKris1224

How to rotate image object in GDI+

Recommended Posts

MrKris1224
Posted (edited)

Hi, i'am making simple 2D "engine" using gdi+ and now i'am trying to make function that will be able to rotate image before i draw it to buffor.

I'am loading images by _GDIPlus_ImageLoadFromFile() then draw them to buffor by _GDIPlus_GraphicsDrawImage() and then copying that buffor to GUI's buffor.

The question is how can i rotate image object before i draw it to buffor?

Edited by MrKris1224

Share this post


Link to post
Share on other sites
MrKris1224

_GDIPlus_ImageRotateFlip() have only 4 angles

_GdiPlus_MatrixRotate() doesn't work for me (image object)

Share this post


Link to post
Share on other sites
InnI
3 hours ago, MrKris1224 said:

doesn't work for me

Really? Strange, but it works for me. What am I doing wrong?

#include <ScreenCapture.au3>

; create temp image file
_ScreenCapture_Capture(@ScriptDir & "\temp.png", 0, 0, 200, 200)

; ----------------

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\temp.png")

$hBuffer = _GDIPlus_BitmapCreateFromScan0(400, 400)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBuffer)

$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixRotate($hMatrix, 20)
_GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 150, 0)

$hGUI = GUICreate("test")
GUISetState()
$hGraph = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraph, $hBuffer, 0, 0)

Do
Until GUIGetMsg() = -3

_GDIPlus_GraphicsDispose($hGraph)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_BitmapDispose($hBuffer)
_GDIPlus_MatrixDispose($hMatrix)

_GDIPlus_Shutdown()

 

  • Like 1

Share this post


Link to post
Share on other sites
MrKris1224

Ok, but this rotatining all of images i drawn. I wanna rotate one image

Share this post


Link to post
Share on other sites
InnI
13 minutes ago, MrKris1224 said:

I wanna rotate one image

See example for _GDIPlus_MatrixRotate in help file.

  • Like 1

Share this post


Link to post
Share on other sites
MrKris1224

Thanks so much i needed exactly that :) Topic to close

Share this post


Link to post
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

×