SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

0
0

Good morning,

i need to draw a bitmap (specifically a RenderTargetBitmap object) to a surface during a Draw method of a CustomRenderableSeries, so using the IRenderContext2D argument.

I see there is a DrawTexture method but can’t find any example on this.
Can you provide a snippet to show the correct use of this method?

Thank you.

WPF project
.Net framework 4.6.1
Schichart 5.5.0.12225

Version
5.5.0.12225
  • You must to post comments
0
0
  • You must to post comments
0
0

I tried both DrawTexture and DrawSprite methods, but the result is always blurred compared to the original bitmap.

  • Andrew Burnett-Thompson
    It will be Luigi unless the image is rendered at the exact same size on screen as the image that you have, and the SciChartSurface has UseLayoutRounding=true / SnapsToDevicePixels=true and is not in any way scaled by WPF’s DPI system
  • You must to post comments
0
0

I put SnapsToDevicePixels = true and UseLayoutRounding = true but still no clue

Here is my code

        private void DrawText(IRenderContext2D renderContext, FormattedText formattedText, double x, double y)
    {
        var sz = new Size(formattedText.Width, formattedText.Height);

        DrawingVisual drawingVisual = new DrawingVisual();
        using (DrawingContext drawingContext = drawingVisual.RenderOpen())
        {
            drawingContext.DrawText(formattedText, new Point(0, 0));
        }

        RenderTargetBitmap bitmap = new RenderTargetBitmap((int)Math.Ceiling(sz.Width), (int)Math.Ceiling(sz.Height), 96, 96, PixelFormats.Pbgra32);
        bitmap.Render(drawingVisual);

        var _pixels = new int[bitmap.PixelWidth * bitmap.PixelHeight];
        bitmap.CopyPixels(_pixels, bitmap.PixelWidth * 4, 0);

        var _texture = renderContext.CreateTexture(bitmap.PixelWidth, bitmap.PixelHeight);

        // Copy pixel data
        _texture.SetData(_pixels);

        // Render
        renderContext.DrawTexture(_texture, new Rect(x, y, bitmap.PixelWidth, bitmap.PixelHeight), TextureFiltering.Linear);
    }
  • Andrew Burnett-Thompson
    Do you wanna open a support ticket with a small sample to reproduce? We can then investigate. Also I notice a performance problem, if you are doing DrawingVisual.DrawText() then drawing that texture to screen it will be slow. If you can cache these bitmaps it will help. We have a built-in DrawText method in RenderContext which is a lot faster, but perhaps lower quality than WPF’s drawing.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.