@Nikita I followed your suggestion. I took a piece of code form some example
var fb = new Framebuffer(PixelFormat.Bgra8888, (int)this.Width, (int)this.Height);
var r = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
using (var target = r.CreateRenderTarget(new object[] { fb }))
{
var bmp = new Bitmap(PixelFormat.Bgra8888, fb.Address, fb.Width, fb.Height, fb.RowBytes);
bmp.Save(@"D:\test1.bmp");
}
fb.Deallocate();
using (var rtb = new RenderTargetBitmap((int)this.Width, (int)this.Height))
{
rtb.Render(this);
rtb.Save(@"D:\test2.png");
}
All bytes in fb.Address are 0. So test1.bmp doesn't contain antything
test2.png is correct
What is wrong?
Thank you
var bmp = new Bitmap(PixelFormat.Bgra8888, fb.Address, fb.Width, fb.Height, fb.RowBytes);
bmp.Save(@"D:\test1.bmp");
fb.Deallocate();
It would probably be better to make the original one to target netstandard
@kekekeks ArthurHub/HTML-Renderer#112
Should I call this function in ui thread or can I call in another thread
It is possible to render on non-UI thread, but that involves quite complex setup
you wrote
"but you can probably render to your video card's framebuffer directly
instead of using intermediate bitmaps
It gives you an IntPtr, right?"
I'm testing the speed of rendering function
Stopwatch stopwatch = new Stopwatch();
var fb = new Framebuffer(PixelFormat.Bgra8888, (int)this.Width, (int)this.Height);
var r = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
using (var target = r.CreateRenderTarget(new object[] { fb }))
using (var ctx = new DrawingContext(target.CreateDrawingContext(null)))
{
stopwatch.Start();
ImmediateRenderer.Render(this, ctx);
Trace.WriteLine(stopwatch.ElapsedMilliseconds);
var bmp = new Bitmap(PixelFormat.Bgra8888, fb.Address, fb.Width, fb.Height, fb.RowBytes);
bmp.Save(@"D:\test1.bmp");
}
fb.Deallocate();
using (var rtb = new RenderTargetBitmap((int)this.Width, (int)this.Height))
{
stopwatch.Restart();
rtb.Render(this);
Trace.WriteLine(stopwatch.ElapsedMilliseconds);
rtb.Save(@"D:\test2.png");
}
ImmediateRenderer.Render seems to be slower than RenderTargetBitmap Render
rtb.Save(@"D:\test2.png");
will be slower than bmp.Save(@"D:\test1.bmp");
Main
method add UseSkia()
after UsePlatformDetect()
netstandar2.0
for HTML-Renderer ArthurHub/HTML-Renderer#112 https://ci.appveyor.com/project/ArthurHub/html-renderer/build/1.5.1.136/artifacts, hopefully it will get merged in main repo :smile: