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!
SkiaSharp has no TIFF support, some resources recommend to add TIFF support using LibTiff.net. That works.
I found some hickups (e.g. using SKEncodedImageFormat.Bmp will break the POC... additionaly I want to point to a solution that is a bit less bumpy using ImageSharp.