Getting a DrawingContext for a wpf WriteableBitmap

前端 未结 5 468
逝去的感伤
逝去的感伤 2020-11-30 05:15

Is there a way to get a DrawingContext (or something similar) for a WriteableBitmap? I.e. something to allow you to call simple DrawLine

5条回答
  •  感情败类
    2020-11-30 05:33

    I'm wondering the same thing, as currently I do something like:

    DrawingVisual drawingVisual = new DrawingVisual();
    using (DrawingContext drawingContext = drawingVisual.RenderOpen())
    {
       //
       // ... draw on the drawingContext
       //
       RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
       bmp.Render(drawingVisual);
       image.Source = bmp;
    }
    

    I'm trying to use the WriteableBitmap to allow multithreaded access to the pixel buffer, which is currently not allowed with neither a DrawingContext nor a RenderTargetBitmap. Maybe some sort of WritePixels routine based off of what you've retrieved from the RenderTargetBitmap would work?

提交回复
热议问题