开发者

Is there bug in the Matrix.RotateAt method for certain angles? .Net Winforms

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 开发者_JAVA百科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.


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.


I had the very same issue, when rotating images, GDI+ shifting the image by 1 pixel, or cropping a 1 pixel border if I try to "fix" the coordinates manually.

Found the solution:

   graphics.SetPixelOffsetMode( Gdiplus::PixelOffsetMode::PixelOffsetModeHalf );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜