I’m using custom method to rotate picture box. This is the code:
public static Image RotateImage(Image img, float rotationAngle)
{
Bitmap bmp = new Bitmap(img.Width, img.Height);
Graphics gfx = Graphics.FromImage(bmp);
gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
gfx.RotateTransform(rotationAngle);
gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
gfx.DrawImage(img, new Point(0, 0));
gfx.Dispose();
return bmp;
}
And this is the call: pictureBox1.Image = RotateImage(pictureBox1.Image, someInt);
Everything is fine at the start, but the more time passes the more transparent image becomes. After a while it’s almost invisible. I found this method at some forum, I haven’t wrote it myself. Any thoughts ?
Any image transformation produces differences between source and destination images due to the interpolation that needs to be used in order to determine each pixel’s color in the rotated image. In your code you are applying transformation each time on the image that you got as a result from the previous transformation effectively multiplying the effect of the interpolation. You should change the approach. You should have somewhere the reference to the original image and always use it to draw the rotated image. For this you should call your method with the angle from the beginning, not relative to the previous image. Something like this: