views:

50

answers:

1

Here's the code i'm using to rotate:

Dim m As New System.Drawing.Drawing2D.Matrix
Dim size = image.Size
m.RotateAt(degreeAngle, New PointF(CSng(size.Width / 2), CSng(size.Height / 2)))
Dim temp As New Bitmap(600, 600, Imaging.PixelFormat.Format32bppPArgb)
Dim g As Graphics = Graphics.FromImage(temp)
g.Transform = m
g.DrawImage(image, 0, 0)

(1) Disposals removed for brevity.
(2) I test the code with a 200 x 200 rectangle.
(3) Size 600,600 it just an arbitrary large value that I know will fit the right and bottom sides of the rotated image for testing purposes.
(4) I know, with this code, the top and left edges will be clipped because I'm not transforming the orgin after the rotate.

The problem only occurs at certain angles:

(1) At 90, the right hand edge disappears completely.
(2) At 180, the right and bottom edges are there, but very faded.
(3) At 270, the bottom edge disappears completely.

Is this a known bug?

If I manually rotate the corners an draw the image by specifying an output rectangle, I don't get the same problem - though it is slightly slower than using RotateAt.

+1  A: 

RotateAt uses formulas and sadness to do rotations, because this is necessary when rotating by anything other than 90 degree increments. If you're going to rotate in 90 degree increments, use RotateFlip, which is much more efficient and more accurate.

Brian
So the solution is to check the angle and use RotateFlip if divisible by 90, otherwise Rotate? This must be a common problem, and I'm surprised I can't find anything on google about it.
Jules
Or add a one pixel border around the entire image set equal to the adjacent pixel before rotating, or crop one extra pixel after rotating, or both. Using RotateFlip is simpler than those solutions, but won't help you when the angle is 89.9 or whatever.
Brian