哪里出了问题?(gdi+)

binfenworld 2009-02-02 09:25:01
/*
* 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);
}
}
}


鼠标画直线,有重影产生。
按思路,应该不会产生重影的,到底哪里出了问题呢?
...全文
56 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
binfenworld 2009-02-03
  • 打赏
  • 举报
回复
为什么背景色为透明会产生重影,我还是没想明白

你能告诉我吗?
优途科技 2009-02-03
  • 打赏
  • 举报
回复
这样合乎逻辑啊。
优途科技 2009-02-03
  • 打赏
  • 举报
回复
呵呵。恭喜lz解决问题。
binfenworld 2009-02-03
  • 打赏
  • 举报
回复
我知道怎么解决重影了
imgPic没有设置背景色,也就是背景色是透明的
设置后就不会产生重影了

可是为什么背景色是透明的就会产生重影呢?
binfenworld 2009-02-02
  • 打赏
  • 举报
回复
谁能帮我解决下啊?
binfenworld 2009-02-02
  • 打赏
  • 举报
回复
代码是根据别人的代码写的
别人的代码在移到画直线不会产生重影

而且我的代码的思路,也是不会产生重影的,但为什么实际运行中产生了重影呢?

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧