tags:

views:

209

answers:

5

Hello,

Does anyone know of a good resource that will show me how to load an image with C++ and spin it?

What I mean by spin is to do an actual animation of the image rotating and not physically rotating the image and saving it.

If I am not clear on what I am asking, please ask for clarification before downvoting.

Thanks

+6  A: 

I would definitely default to OpenGL for this type of task, you can load the image into a Texture, then either redraw the image at different angles, or better yet you can just spin the 'camera' in the OpenGL engine. There are loads of OpenGL tutorials around, a quick google search will get you everything you need.

DeusAduro
okay thanks, i will check out openGL and go from there.
Jason Heine
A: 

i agree with DeusAduro. OpenGL is a good way of doing this.

you can also do this with Qt

ufukgun
i dont know why someone downvote here, i did such a think in qt. i needed something like that in qt. anyway i suggested openGL. i think it is a strange behaviour.
ufukgun
A: 

The "roll-your-own" solution is difficult.

I'd suggest looking into WPF - it might have some nice options in an image control.

Paul Nathan
Using WPF from C++ is awesome :)
Kirill V. Lyadvinsky
+1  A: 

In Windows using GDI+ you could show rotated image in the following way:

Graphics graphics( GetSafeHwnd() ); // initialize from window handle
// You can construct Image objects from a variety of 
// file types including BMP, ICON, GIF, JPEG, Exif, PNG, TIFF, WMF, and EMF.
Image image( L"someimage.bmp" );    

graphics.RotateTransform( 30.0f );  // 30 - angle, in degrees.
graphics.DrawImage( &image, 0, 0 );   // draw rotated image

You could read here more detailed explanation.


Second solution is to use DirectX. You could create texture from file and later render it. It is not trivial solution, but it'll use hardware acceleration and will give you the best performance.


On Windows 7 there is available new API called Direct2D. I have not used it yet, but it looks promising.

Direct2D provides Win32 developers with the ability to perform 2-D graphics rendering tasks with superior performance and visual quality.

Kirill V. Lyadvinsky
Is this fast enough to look animated?
Mark Ransom
It is fast enough if you'll use cached bitmap and double buffering.
Kirill V. Lyadvinsky
+2  A: 

You could use SDL and the extension sdl_image and/or sdl_gfx

DaClown
SDL worked perfect. Thanks!
Jason Heine