Drawing line using WPF WriteableBitmap.BackBuffer

元气小坏坏 提交于 2020-01-21 08:15:13

问题


Do you know any library that provides methods to draw simple shapes (lines and optionally other shapes) using WPF WriteableBitmap and ideally BackBuffer? I know that there is a WriteableBitmapEx project for silverlight but is there WPF equivalent?


回答1:


I guess here is the answer to my question :)

_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();



回答2:


You seem to be using Bitmap, but asking for a solution using WriteableBitmap. There is a WriteableBitmapEx for WPF.



来源:https://stackoverflow.com/questions/3000591/drawing-line-using-wpf-writeablebitmap-backbuffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!