GDI+ Poor Quality when rotating pictures

cotecmania
02-18-2005, 08:06 AM
Hi,

i modified an existing GDI+ example to do rotation to pictures.
If i rotate an example picture four times for 90 degress the result is much worse than the beginning.
I attached a demo project. Press four times the rotate button an then the reset button to see the difference, or do rotation much more.
I need a possibility to rotate pictures without loss of quality e.g. to switch a photogtraph from landscape to portrait.

Thanks in Advance
Joe

@OnError
Thank you for your help with GDI+.
Where can i get some information about using the GDI-Functions ?

OnErr0r
02-18-2005, 09:45 AM
The loss of quality is from constantly creating and destroying the bitmap. I would change your routines to accept a bitmap class instance as a parameter. The graphics class can be created and destroyed without any problem.

Also, use Bitmap.RotateFlip for various rotations of 90/180/270 degrees, instead of RotateTransform.

I don't see any code to Set gdip = Nothing, this is usually done in the form_unload event.

MS has very little about GDI+ flat posted. What little they do have is for C++: http://msdn.microsoft.com/library/en-us/gdicpp/GDIPlus/GDIPlusreference/flatapi.asp

OnErr0r
02-18-2005, 09:50 AM
I should also mention, Graphics.SetInterpolationMode with InterpolationModeHighQualityBilinear or InterpolationModeHighQualityBicubic will increase the quality with which images are drawn by DrawImage.

passel
02-18-2005, 09:35 PM
A common mistake people make is to rotate an already rotated image.
Each time you rotate, artifacts are introduced into the resulting picture. Each further
rotation will degrade the image further. The proper way is to keep the original picture
intact and rotate the original image to the accumulated angle, i.e. if you rotate the
image 10 degrees, 3 times, you rotate the original image by 10 degrees, then you
rotate the original image by 20 degrees, and then the original by 30 degrees. Always
start with a clean original, or the image will eventually dissolve into soup.

OnErr0r
02-19-2005, 01:49 AM
Good point passel. And that's exactly what he was seeing in drawing and recreating from the drawn image. I didn't do that in my original example.

Luckily, the bitmap RotateFlip is on the original bitmap and should be lossless.

borax
02-20-2005, 01:48 PM
I need a possibility to rotate pictures without loss of quality e.g. to switch a photogtraph from landscape to portrait.

If you want to rotate photos (from digital cameras) in JPEG format have a look here:
http://sylvana.net/jpegcrop/jpegtran/

cotecmania
02-21-2005, 04:47 AM
Hi,

I know that it is better to rotate for 180 degrees once than two times for 90 degrees !!!
I modified in this way to demonstrate HOW bad the loss of quality is !

If you do only one rotation of 90 degrees you probably won't see the loss of quality with your eyes.

Now i tested the RotateFlip-Command and this worked fine.
Even if i do 4 times 90 degrees !!!

Thanks
Joe

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum