printpdf
printpdf copied to clipboard
png with transparency/alpha channel wouldn't shown
printpdf version: 0.3.3
If I try to add a png with transparency, the image wouldn't shown. Other png files works fine.
let mut image_file = File::open("test.png").unwrap();
let image = Image::try_from(image::png::PngDecoder::new(&mut image_file).unwrap()).unwrap();
image.add_to_layer(current_layer.clone(), Some(Mm(x)), Some(Mm(y)), None, Some(1.0), Some(1.0), Some(300.0));
Can you upload the PNG file to GitHub?
As far as I know, images with an alpha channel aren't supported right now because that would require support for "soft masks" in the PDF, which isn't implemented yet.
Also see https://github.com/fschutt/printpdf/issues/61
It really seems to be the problem/reason you described.
I'm putting soft masks on my todo list, it's not that hard to implement (you need to split out the alpha channel and then reference it as a separate greyscale image). Can't say when I'll get back to working on printpdf though.
for newcomer going here, this is the workaround https://github.com/fschutt/printpdf/issues/119#issuecomment-1120434233 (work only with Rgba color space)