Drawing line using WPF WriteableBitmap.BackBuffer

后端 未结 2 541
余生分开走
余生分开走 2021-01-14 17: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 i

相关标签:
2条回答
  • 2021-01-14 17:38

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

    0 讨论(0)
  • 2021-01-14 17:46

    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();
    
    0 讨论(0)
提交回复
热议问题