使用 WPF WriteableBitmap.BackBuffer 绘制线条

3

你知道有哪些库可以使用WPF WriteableBitmap和理想的BackBuffer来绘制简单的形状(线条和其他形状)的方法吗? 我知道Silverlight有WriteableBitmapEx项目,但是是否有WPF等效项目呢?


2个回答

7

我猜这里就是我的问题的答案 :)

_plotBitmap.Lock();

var b = new Bitmap(_plotBitmap.PixelWidth,
                   _plotBitmap.PixelHeight,
                   _plotBitmap.BackBufferStride,
                   System.Drawing.Imaging.PixelFormat.Format24bppRgb, 
                   _plotBitmap.BackBuffer);

using(var bitmapGraphics = System.Drawing.Graphics.FromImage(b))
{
    bitmapGraphics.SmoothingMode = SmoothingMode.HighSpeed;
    bitmapGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
    bitmapGraphics.CompositingMode = CompositingMode.SourceCopy;
    bitmapGraphics.CompositingQuality = CompositingQuality.HighSpeed;
    bitmapGraphics.DrawLine(Pens.Gold,2,2,222,222);
}

_plotBitmap.AddDirtyRect(new Int32Rect(0,0,_plotBitmap.PixelWidth,_plotBitmap.PixelHeight));
_plotBitmap.Unlock();

4
不需要显式Dispose()位图对象,这就是using语句的设计初衷。 - Dercsár

2

看起来你正在使用Bitmap,但要求使用WriteableBitmap的解决方案。WPF有WriteableBitmapEx可供使用。


WriteableBitmapEx的性能不是最佳的,而且不能绘制文本;它只有更好的抗锯齿系统适用于线条,如果你需要的话。 - Виталий Семеняко

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接