在c#中如何实现图象的移动旋转的效果
展开全部
Bitmap bmp;//源图
Bitmap background;//背景位图
Timer timer1;//定时旋转和移动
Graphics g;//背景图的画图对象
float x = 0;//水平移动的初始位置
private void pictureBox1_Click(object sender, EventArgs e)
{
bmp=new Bitmap(@"..\..\1.bmp");
background = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//画在PictureBox上
g = Graphics.FromImage(background);
g.TranslateTransform(background.Width / 2, background.Height / 2);//移动一下中心点,画在背景的中央,好看些
timer1 = new Timer();
timer1.Interval = 100;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Enabled = true;
}
void timer1_Tick(object sender, EventArgs e)
{
g.Clear(Color.Black);
g.RotateTransform(10.0F);//每次旋转10度,实际上是画图坐标旋转
g.DrawImage(bmp, -bmp.Width/2, -bmp.Height/2);//源图中心点和画图对象中心重合,自旋转效果,否则会以左上角为中心旋转
Graphics gb=pictureBox1.CreateGraphics();
x += 3.0f;//水平移动效果,步长3像素
gb.DrawImage(background,x,0.0f);
}
Bitmap background;//背景位图
Timer timer1;//定时旋转和移动
Graphics g;//背景图的画图对象
float x = 0;//水平移动的初始位置
private void pictureBox1_Click(object sender, EventArgs e)
{
bmp=new Bitmap(@"..\..\1.bmp");
background = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//画在PictureBox上
g = Graphics.FromImage(background);
g.TranslateTransform(background.Width / 2, background.Height / 2);//移动一下中心点,画在背景的中央,好看些
timer1 = new Timer();
timer1.Interval = 100;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Enabled = true;
}
void timer1_Tick(object sender, EventArgs e)
{
g.Clear(Color.Black);
g.RotateTransform(10.0F);//每次旋转10度,实际上是画图坐标旋转
g.DrawImage(bmp, -bmp.Width/2, -bmp.Height/2);//源图中心点和画图对象中心重合,自旋转效果,否则会以左上角为中心旋转
Graphics gb=pictureBox1.CreateGraphics();
x += 3.0f;//水平移动效果,步长3像素
gb.DrawImage(background,x,0.0f);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询