2
我試圖製作一個在c#中使用定時器的輪子動畫(pictureBox上的輪子圖像)。旋轉圖像的在定時器上旋轉圖像而不混合圖像
方法:
public static Image RotateImage(Image img, float rotationAngle)
{
//create an empty Bitmap image
Bitmap bmp = new Bitmap(img.Width, img.Height);
//turn the Bitmap into a Graphics object
Graphics gfx = Graphics.FromImage(bmp);
//now we set the rotation point to the center of our image
gfx.TranslateTransform((float)bmp.Width/2, (float)bmp.Height/2);
//now rotate the image
gfx.RotateTransform(rotationAngle);
gfx.TranslateTransform(-(float)bmp.Width/2, -(float)bmp.Height/2);
//set the InterpolationMode to HighQualityBicubic so to ensure a high
//quality image once it is transformed to the specified size
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
//now draw our new image onto the graphics object
gfx.DrawImage(img, new Point(0, 0));
//dispose of our Graphics object
gfx.Dispose();
//return the image
return bmp;
}
//爲計時器滴答
private void timer1_Tick(object sender, EventArgs e)
{
float anglePerTick = 0;
anglePerTick = anglePerSec/1000 * timer1.Interval;
pictureBox1.Image = RotateImage(pictureBox1.Image, anglePerTick);
}
代碼輪的圖像保持紡絲和顏色被混合,然後將圖像剛剛淡出。 我該如何解決這個問題?
什麼是'anglePerSec'值,什麼是'timer1.Interval'值?你有沒有嘗試增加間隔? – SergeyS