Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for PNG Transparency #45

Merged
merged 2 commits into from
Jul 13, 2019
Merged

Conversation

Sappharad
Copy link
Contributor

This is not the best way to solve this, as we need to load the images to determine if they're transparent PNG prior to actually using them. We could use ReadMetaData to determine if they're transparent but that would require re-working the image source stuff to allow reading ahead of time without loading.

Also ignores all of the other supported formats that could have transparency, but it's clearer now how you can make that work.

@Sappharad
Copy link
Contributor Author

Sappharad commented Jul 10, 2019

Looks like this still needs some work. It seems to be processing some of my JPEG as PNG, resulting in larger than expected PDF files. (The PDF's still look correct.)

I don't recommend accepting this until I fix it.

@Sappharad
Copy link
Contributor Author

Okay, my latest commit got this to where I think it works as expected. I had to modify the ImageSource class some more because the ImageSharp Load() method has an overload that returns file format and that was the only reliable way to detect PNG. All images loaded through the generic Load() method that don't explicitly specify a color depth end up as RGBA32, which caused my previous attempt to detect everything as transparent. My new approach actually uses to file type returned via Load(), if it is PNG is set the new Transparent flag on ImageSource and we embed the image in the PDF as a PDF Bitmap with Transparency instead of converting it to JPEG. This is basically equivalent to what the GDI PDFSharp does for PNG.

We still need to load images up front to know what format they are, but honestly I don't see this as a problem because they were getting loaded anyway during render, we're just doing it sooner now.

When I mix PNG and JPEGs in the PDF, the JPEG stays JPEG and the PNG has transparency.

As far as I know, everything works as I'd expect now so let me know if you think more changes are required to meet your standards.

Thanks!

@ststeiger ststeiger merged commit 29d9556 into ststeiger:master Jul 13, 2019
@ststeiger
Copy link
Owner

Thanks, merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants