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
- Luigi Casiglio asked 4 years ago
- You must login to post comments
Hi Luigi
This has been asked a couple of times before. Do these links help?
https://www.scichart.com/questions/wpf/how-to-display-an-image-using-a-drawtexture-and-itexture2d
https://www.scichart.com/questions/wpf/rendering-2d-camera-images
Best regards,
Andrew
- Andrew Burnett-Thompson answered 4 years ago
- You must login to post comments
I tried both DrawTexture and DrawSprite methods, but the result is always blurred compared to the original bitmap.
- Luigi Casiglio answered 4 years ago
-
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 login to post comments
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);
}
- Luigi Casiglio answered 4 years ago
- last edited 4 years ago
-
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 login to post comments
Please login first to submit.