![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all, I had been been trying for the double buffering technique to draw line on movement of mouse on pictureBox.The following is the piece of code: private void pictureBox1_MouseMove(object sender,MouseEventArgs e) { if(e.Button==MouseButtons.Left) { Bitmap backbuffer=new Bitmap(pictureBox1.Width,pictureBox1.Height); Graphics bckgphcs=Graphics.FromImage(backbuffer); Graphics picgphcs=pictureBox1.CreateGraphics(); SolidBrush redbrush=new SolidBrush(Color.Red); Pen redpen=new Pen(redbrush,2); endpoint.X=e.X;endpoint.Y=e.Y; bckgphcs.DrawImage(pictureBox1.Image,0,0); bckgphcs.DrawLine(redpen,startpoint,endpoint); picgphcs.DrawImage(backbuffer,0,0); bckgphcs.Dispose(); picgphcs.Dispose(); backbuffer.Dispose(); redbrush.Dispose();redpen.Dispose(); } It works well when I try for the first time.As I do it again and again,my CPU resources shoot upto 100% and line drawing becomes slow. Is there any way out???? regards Rithesh |
#3
| |||
| |||
|
|
Hi all, I had been been trying for the double buffering technique to draw line on movement of mouse on pictureBox.The following is the piece of code: private void pictureBox1_MouseMove(object sender,MouseEventArgs e) { if(e.Button==MouseButtons.Left) { Bitmap backbuffer=new Bitmap(pictureBox1.Width,pictureBox1.Height); Graphics bckgphcs=Graphics.FromImage(backbuffer); Graphics picgphcs=pictureBox1.CreateGraphics(); SolidBrush redbrush=new SolidBrush(Color.Red); Pen redpen=new Pen(redbrush,2); endpoint.X=e.X;endpoint.Y=e.Y; bckgphcs.DrawImage(pictureBox1.Image,0,0); bckgphcs.DrawLine(redpen,startpoint,endpoint); picgphcs.DrawImage(backbuffer,0,0); bckgphcs.Dispose(); picgphcs.Dispose(); backbuffer.Dispose(); redbrush.Dispose();redpen.Dispose(); } It works well when I try for the first time.As I do it again and again,my CPU resources shoot upto 100% and line drawing becomes slow. Is there any way out???? regards Rithesh |
#4
| |||
| |||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |