.NET 6: Transitioning from System.Drawing to SkiaSharp for Tiff to PDF conversion

Viewed 22

I am trying several ways to remove System.Drawing due to the pending removal of the workaround in .NET 7. I am trying to use SkiaSharp to replace those calls but am having trouble.

The following is what I currently have, which processes Tiff data from a stream and passes it to PdfSharp to construct the final Pdf:

   System.Drawing.Image MyImage = System.Drawing.Image.FromStream(inStream);
   PdfDocument doc = new PdfDocument();

   for (int PageIndex = 0; PageIndex < MyImage.GetFrameCount(FrameDimension.Page); PageIndex++)
   {
     MyImage.SelectActiveFrame(FrameDimension.Page, PageIndex);
     XImage img = XImage.FromGdiPlusImage(MyImage);
     var page = new PdfPage();

     doc.Pages.Add(page);
     XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[PageIndex]);
     xgr.DrawImage(img, 0, 0);
   }

   doc.Save(outStream);
   MyImage.Dispose();

I am not sure what the SkiaSharp equivalents would be and have tried searching for them in the docs.

If you have any questions, concerns, or comments, please let me know. Thanks!

0 Answers
Related