C# 使用自定义旋转方法时的图像淡入淡出

C# 使用自定义旋转方法时的图像淡入淡出,c#,winforms,image,picturebox,C#,Winforms,Image,Picturebox,我正在使用自定义方法旋转图片框。代码如下: 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, (

我正在使用自定义方法旋转图片框。代码如下:

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;
    }
这就是调用:
pictureBox1.Image=RotateImage(pictureBox1.Image,someInt)


开始时一切正常,但时间越长,图像越透明。过了一会儿,它几乎看不见了。我在某个论坛上找到了这个方法,我还没有自己写过。有什么想法吗

由于需要使用插值来确定旋转图像中每个像素的颜色,因此任何图像变换都会在源图像和目标图像之间产生差异。在您的代码中,您每次都在图像上应用变换,该图像是前一次变换的结果,有效地乘以插值的效果。你应该改变方法。您应该在某个地方有对原始图像的引用,并始终使用它来绘制旋转后的图像。为此,您应该从开始的角度调用方法,而不是相对于前一幅图像。大概是这样的:

static int someInt = 5;
Bitmap bmp = new Bitmap(@"someImage.jpg");
private void button2_Click(object sender, EventArgs e)
{
      pictureBox1.Image = RotateImage(bmp, someInt);
      someInt = (someInt + 5) % 360;
}