Rotating Images

B

Brian Adams

I am working on an image viewer application as a learning
exercise. Obviously I am making heavy use of the Bitmap
and Image classes. In the full framework, there is a
method called Image.RotateFlip() that would allow some
trivial image manipulation. This method doesn't exist in
the Compact Framework. Unfortunately, they also removed
the LockBits method that would allow programmers to party
on the image bits themselves. The only way I have found
in the Compact Framework to rotate an image is by creating
a second image of the correct dimensions and then walking
over the first image calling GetPixel and then calling
SetPixel on the new image. This is just about the most
inefficient method of doing anything I have ever
witnessed. To rotate a simple 74x124 pixel image on a
400MHz XScale, it takes approx. 1:30 minutes. The time to
rotate an image 90 degrees appears to increase
exponentially as the image gets larger.

Does anybody have a better method of rotating an image
with the Compact Framework? If not, then I fear it will
be a big flop for the majority of applications, since
trivial image manipulation is a fairly common thing.
Especially with games!

Brian
 
P

Peter Foot [MVP]

Brian Adams said:
Does anybody have a better method of rotating an image
with the Compact Framework? If not, then I fear it will
be a big flop for the majority of applications, since
trivial image manipulation is a fairly common thing.
Especially with games!

You may wish to check out Alex Feinman's article on accessing the Bitmaps
internal data
http://www.opennetcf.org/Articles/GdiObjects.asp

I'm not sure from memory that the article described rotation in particular
but manipulating the bitmap data directly will give better performance than
the GetPixel SetPixel route. Of course this is delving into the undocumented
innards of the Bitmap class so your code may not work on future updates to
the compact framework.

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
 
B

Brian Adams

Thanks for the info. I found the opennetcf.org site to be
quite useful. He didn't discuss rotation directly, but
what he provided definitely makes it possible to do it
myself. I am curious about how the Garbage Collection
will affect anything that the GDIInternals class is
accessing. If I were to use the hBitmap member and
retrieve a DIBSECTION, would a garbage collection move any
memory around in such a way that that the memory I am
manipulationg is no longer valid?

Brian
 
S

SeanC

Does anybody have a better method of rotating an image
with the Compact Framework? If not, then I fear it will
be a big flop for the majority of applications, since
trivial image manipulation is a fairly common thing.
Especially with games!

Brian

For games and similar apps where full screen is acceptable, see my
gapidraw wrapper at http://www.Intuitex.com.

Sean
---------------------------------------
Sean Cross
mailto:[email protected]

Pics Print - The photo printing solution for Windows.
http://www.picsprint.com

http://www.Intuitex.com -
Multimedia software for Windows
Game libraries for the dot net compact framework
 
R

Romu

Brian, Peter, I already tried to implement a better
method to rotate images, I found a simple article (in VB)
in the MSDN, I translated it in C# and tried to use the
Alex article to save this new bitmap.

The problem is the one I described in the OpenCFForum, I
can't save the bitmap because the new rotated image is
not created as a DIBSECTION.

I can discuss this point and give my code to rotate, I
someone finds a solution to save the bitmap... Great !!!
 
B

Brian Adams

I would love to see your solution! I'll do my best to
figure out how to save it back to a Bitmap.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top