日期:2014-05-17  浏览次数:21026 次

C#如何解决带透明度画笔的“青蛙卵”现象,速度仍然流畅?
我用GDI+做带有透明度的画笔,实现后出现“青蛙卵”现象,目前有方法解决,但是速度不流畅,会滞后,希望有高人能把青蛙卵解决了 ,同时速度又不受影响的。

下面贴了代码 只是实现带透明度功能。需要解决有透明度时,不会出现青蛙卵,速度也不受影响。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Alpha_Pen
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  Point startPoint,secondPoint;
  bool drawMove;
  Pen pen;
  Bitmap bit;
  Graphics g;
  private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  {
  if (e.Button == MouseButtons.Left)
  {
  startPoint = new Point(e.X, e.Y);
  drawMove = true;
  }
  }

  private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  {
  if (drawMove)
  {
  pen = new Pen(Color.FromArgb(128,255,0,0),20);
  pen.StartCap = LineCap.Round;
  pen.LineJoin = LineJoin.Round;
  pen.EndCap = LineCap.Round;
  secondPoint = new Point(e.X,e.Y);  
   
  g.DrawLine(pen,startPoint.X,startPoint.Y,secondPoint.X,secondPoint.Y);
  startPoint = secondPoint;
  pictureBox1.Invalidate();
   
  }  
  }

  private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
  {
  drawMove = false;
  }

  private void pictureBox1_Paint(object sender, PaintEventArgs e)
  {
  if (bit != null)
  {
  e.Graphics.DrawImage(bit, 0, 0);
  }

  }

  private void Form1_Load(object sender, EventArgs e)
  {
  pictureBox1.Width = 1920;
  pictureBox1.Height = 1080;
  bit= new Bitmap(pictureBox1.Width, pictureBox1.Height);
  g = Graphics.FromImage(bit);
   

  }




  }
}


------解决方案--------------------
楼主!
你可以在paint事件里实时刷新改成局部刷新,整个全部刷新速度会慢。
你可以根据第一点和第二点两点确定一个矩形,然后在paint中只刷新改矩形区域!