我正在使用C#/ .Net中的简单矢量绘图应用程序.绘图是在一个面板中完成的,但是我并没有对所有这些事件使用OnPaint()事件 - 实际上OnPaint()甚至只调用另一个实际绘制文档中所有内容的方法.
我尝试添加双缓冲,但是当我将DoubleBuffered设置为true时,闪烁问题更加严重.为什么是这样?如果我想双重缓冲控件,我是否必须使用提供的Graphics对象在OnPaint()事件中完成所有绘图,而不是使用Panel.CreateGraphics()然后绘制到那个?
编辑:这是我正在使用的基本代码.
private void doc_Paint(object sender, PaintEventArgs e)
{
g = doc.CreateGraphics();
Render(ScaleFactor, Offset);
}
private void Render(float ScaleFactor, PointF offset)
{
foreach (Line X in Document.Lines) { DrawLine(X.PointA, X.PointB, X.Color, X.LineWidth); }
}
private void DrawLine(PointF A, PointF B, Color Color, float Width)
{
Pen p = new Pen(Color, Width);
PointF PA = new PointF(((A.X + Offset.X) * ScaleFactor), ((A.Y + Offset.Y) * ScaleFactor));
PointF PB = new PointF(((B.X + Offset.X) * ScaleFactor), ((B.Y + …Run Code Online (Sandbox Code Playgroud) 我试图在图像上绘制带有反色的十字准线("加号"),以显示图像中所选点的位置.我是这样做的:
private static void DrawInvertedCrosshair(Graphics g, Image img, PointF location, float length, float width)
{
float halfLength = length / 2f;
float halfWidth = width / 2f;
Rectangle absHorizRect = Rectangle.Round(new RectangleF(location.X - halfLength, location.Y - halfWidth, length, width));
Rectangle absVertRect = Rectangle.Round(new RectangleF(location.X - halfWidth, location.Y - halfLength, width, length));
ImageAttributes attributes = new ImageAttributes();
float[][] invertMatrix =
{
new float[] {-1, 0, 0, 0, 0 },
new float[] { 0, -1, 0, 0, 0 },
new float[] { …Run Code Online (Sandbox Code Playgroud)