1SaeedSalehi
1SaeedSalehi

Reputation: 373

Is there any way to convert SKDocument to SKbitmap?

i am looking for a way to convert a SKDocument which has created a pdf just like this SKDocument.CreatePdf(ManagedStreamForPdfMemoryStream); to an image equivalent like SKBitmap

Upvotes: 0

Views: 1017

Answers (1)

Matthew
Matthew

Reputation: 5222

That is not possible, the SKDocument.CreatePdf generates a PDF file that cannot be read a a bitmap with SkiaSharp.

As I mention in this answer, I would suggest looking for ways to load PDFs without associating with SkiaSharp - they are different tasks. https://stackoverflow.com/a/59513162/1117914

BUT...

If you are creating a PDF using SkiaSharp, then just use that same logic you used to create the PDF to create the bitmaps.

You can even use something like the SKNWayCanvas to draw in parallel: https://learn.microsoft.com/dotnet/api/skiasharp.sknwaycanvas

var pdf = document.BeginPage();
var bmp = imageSurface.Canvas;

var canvas = new SKNWayCanvas(100, 100);
canvas.AddCanvas(pdf);
canvas.AddCanvas(bmp);

canvas.DrawRect(...); 

At the end, you will have a PDF and a set of bitmaps that you can render on screen. No extra work required and no need to load files.

Upvotes: 1

Related Questions