哪里出了问题?(gdi+)
/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2009-2-2
* Time: 20:26
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DrawG
{
/// <summary>
/// Description of Box2.
/// </summary>
public partial class Box2 : Form
{
protected Image imgPic;
protected Point pS,pE;
protected Graphics temG;
protected Image imgTem;
protected Pen p;
protected bool flag=false ;
public Box2()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
p=new Pen (Color.Blue ,2);
imgPic =new Bitmap (pbImg .Width ,pbImg .Height );
imgTem =(Image )imgPic.Clone () ;
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void PbImgMouseDown(object sender, MouseEventArgs e)
{
pS =new Point (e.X ,e.Y );
flag =true ;
}
void PbImgMouseMove(object sender, MouseEventArgs e)
{
if (flag )
{
pE =new Point (e.X,e.Y );
Image img=(Image )imgPic .Clone ();
temG =Graphics .FromImage (img );
temG .DrawLine (p,pS ,pE );
temG .Dispose ();
temG =Graphics .FromImage (imgTem );
temG .DrawImage (img,0,0);
temG .Dispose ();
pbImg .CreateGraphics ().DrawImage (img ,0,0);
img .Dispose ();
}
}
void PbImgMouseUp(object sender, MouseEventArgs e)
{
flag =false ;
temG =Graphics .FromImage (imgPic );
temG .DrawImage (imgTem,0,0);
temG .Dispose ();
}
void PbImgPaint(object sender, PaintEventArgs e)
{
Graphics g=e.Graphics ;
g.DrawImage (imgPic ,0,0);
}
}
}
鼠标画直线,有重影产生。
按思路,应该不会产生重影的,到底哪里出了问题呢?