I wanted to include PNG images with transparency in my PDFs, but I was getting some very ugly black backgrounds. After checking the code I realized that although the original PDFSharp supported multiple image types, the Xamarin fork this one is based on had stripped out that support, and forces all images to be treated as JPEGs.
This PR restores some of the original PDFSharp support for other image types, modified to work with the new ImageSource interface. The implementation is relatively fragile. I've tested it with PNGs and GIFs (transparency works in PNG, but not with GIF), but only on Windows desktop, and only with an ImageSharp implementation of ImageSource, and only with 32 bit images. I prefer to leave improvements for handling any edge cases or refinements to future PRs from others with greater expertise in the various platform-specific code, and image and PDF format specs.
I've also modified the test project to include a transparent PNG on the test document. This introduces a dependency on ImageSharp for the ImageSource to the test project. If that is undesirable, the changes to the test project could easily be omitted.
I wanted to include PNG images with transparency in my PDFs, but I was getting some very ugly black backgrounds. After checking the code I realized that although the original PDFSharp supported multiple image types, the Xamarin fork this one is based on had stripped out that support, and forces all images to be treated as JPEGs.
This PR restores some of the original PDFSharp support for other image types, modified to work with the new ImageSource interface. The implementation is relatively fragile. I've tested it with PNGs and GIFs (transparency works in PNG, but not with GIF), but only on Windows desktop, and only with an ImageSharp implementation of ImageSource, and only with 32 bit images. I prefer to leave improvements for handling any edge cases or refinements to future PRs from others with greater expertise in the various platform-specific code, and image and PDF format specs.
I've also modified the test project to include a transparent PNG on the test document. This introduces a dependency on ImageSharp for the ImageSource to the test project. If that is undesirable, the changes to the test project could easily be omitted.