Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
My image didnot move smoothly, please help me.
k
16y
5.5k
1
Reply
I try to make small image movable, but it didnot move smoothly. Anyone can help me?
Thanks in advance.
My project:
http://www.adrive.com/public/cb65f291603e8...2ce7200841.html
namespace ImageMoving
{
public class car
{
public Image pic;
public int x;
public int y;
public car()
{
pic = Image.FromFile("myimage.jpg");
}
}
public partial class Form1 : Form
{
Timer MyTimer = new Timer();
car MyCar = new car();
Image imgbg;
public Form1()
{
InitializeComponent();
imgbg = Image.FromFile("background.jpg");
MyCar.x = 0;
MyCar.y = 0;
MyTimer.Interval = 20;
MyTimer.Start();
MyTimer.Tick += new EventHandler(MyTimer_Tick);
}
void MyTimer_Tick(object sender, EventArgs e)
{
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
Image imgBuffer = new Bitmap(this.Width, this.Height);
Graphics grBuffer = Graphics.FromImage(imgBuffer);
grBuffer.DrawImage(imgbg, 0, 0);
using (grBuffer)
{
grBuffer.DrawImage(MyCar.pic, MyCar.x, MyCar.y);
MyCar.x += 5;
e.Graphics.DrawImage(imgBuffer, 0, 0);
}
imgBuffer.Dispose();
}
}
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Sphere in C# without DirectX mapped by a texure jpg or bmp file
DrawImage Artifacts