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?
            Asked
            
        
        
            Active
            
        
            Viewed 7,483 times
        
    3
            
            
        - 
                    Related: [How to get a DrawingContext for a WriteableBitmap](http://stackoverflow.com/questions/88488/getting-a-drawingcontext-for-a-wpf-writeablebitmap) – Roman Starkov Jan 03 '12 at 12:24
 
2 Answers
7
            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();
- 
                    4You don't need to explicitly Dispose() the bitmap. This is what using is designed for. – Dercsár Jan 15 '12 at 13:11
 
2
            
            
        You seem to be using Bitmap, but asking for a solution using WriteableBitmap. There is a WriteableBitmapEx for WPF.
        Guy
        
- 1,232
 - 10
 - 21
 
- 
                    WriteableBitmapEx has not optimal perfomance, and cannot draw text; it has better antialias system for lines only, if you need in it. – Виталий Семеняко Sep 21 '15 at 09:00