i’m working on a project that uses rsfpdf.
Because of this I need to create .png images without alpha channel. To show what I want, I’ve created a small project that shows what I want (create png without Alpha Channel):
The main problem I have is in Windows platform. It works perfectly on Mac (generates .png without alpha channel, you can check the output with (sips -g all / pathtogenerated_png_Desktop), but in Windows the output still generates a png with alpha channel. I would not like to use ImageMagik in Windows (would generate an installer too heavy for Windows.) Do you have any ideas?
Checked under Xojo 2015r1 / Windows XP: no alpha channel !
Edit (additions):
PS: I had to comment your ratio If test block.
A second image drop in the left Canvas is draw above the previous drop;
No rectangle displayed around the Canvas
I suppose the project is a simple test project.
yes (it´s a simple test), and 24-bit Depth instead of 32-bit because:
samples per pixel: R (1) G(1) B(1) A(1)
bitsPersample: 8
so if you take care about A samplepp (Alpha Channel) you obtain 4 samples per pixel * 8(bitspersample)=32
i’m trying to avoid A, so: sample per pixel 1 x R + 1 x G + 1 x B = 3 * 8(bitspersample)=24
I think your best best for a PDF solution would be to use JPEG instead of PNG…
A simple conversion from PNG to JPEG will remove the alpha channel as well…
This is exactly what my gPDF class does, regardless of the image type you supply, it internally converts to JPEG to become part of the document
As long as you create it this way and not by letting the Picture.Open make it then it looks like the image has no alpha channel until its written to disk, as you can’t change the routine that saves the image to disk (without getting into declares) it might just be easier to modify the rsfpdf code in parsePNG so it reads the image into a picture that has been constructed without an alpha channel then have the function read the data from memory instead.
This should then work for all files passed to rsfpdf, there’s a small overhead on this because you’re reading it all in then reading through it again, but the performance loss will hardly be noticeable.
[quote=386613:@Emile Schwarz]Dirk: Cesar said 32 bits have Alpha Channel.
I told him to try (I know this works and I tested it).
Edit: Read his answer far above.[/quote]
I’m telling him this is part of what he needs.
He needs to split it into a mask and an image.
The mask needs to be grayscale
Dim alpha_img As Picture
alpha_img=poImage.CopyMask
alpha_img=InvertPicture(alpha_img)
Then he needs to have his image like I did in the code above.
Then he needs to create the datastream for the mask (with /DeviceGray and /SMAsk) and the actual image.
Based on the OP… is the question really about removing the Alpha Channel? or is it about trying to use a PNG in creating a PDF document?
If the latter (creating a PDF)… then the simplest thing is as I mentioned, convert it to a JPEG, since that is the internal format that works best with the PDF specification.
I know @Björn Eiriksson does not like to “promote” his Solutions by himself in the Forum, but i use his PDF Plugin and embed Xojo Images and external Pictures in PDF’s using his Plugin. Was not so hard to accomplish this and i am for sure not the most experienced Xojo Dev…
I think it’s about removing the alpha channel because that is not really supported in PDF
But then you’d lose your transparency, and that might not be what you want (for instance if you have a watermark in the background. it’s not nice to have a nice watermark with an image with white border instead of transparent border over top of said watermark.)
I think the main problem is that when you save the png in Xojo, the file contains an alpha channel when you load it.
To work around that, I used either a mask and an image (PNGWriterMBS not needed), or I used a png with alpha, but saved the necessary files with the PNGWriterMBS class and embedded those (the PNGWriterMBS saves the needed greyscale mask and RGB version of the actual image (without an alpha channel).
That way I can use alpha channel png’s and keep the transparency in the pdf.