Removing alpha Channel

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):

https://github.com/clmmakers/alphachannelremover

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?

thanks in advance.

I do not checked your project, but are-you sure that add an alpha channel ?

Picture.Constructor(width as Integer, height as Integer, Depth as Integer)

In Windows -> yes keeps/creates an alpha channel.
In Os X ->runs as expected.

I’ve tested (picture.mask=nil) too (https://forum.xojo.com/30893-save-a-picture-object-without-alpha-channel/0#p253307)
The same problem in Windows.

Thanks.

How can you tell you have an alpha channel on Windows ?
What Windows OS version ?

What Xojo version ?

I will check your project once I finished the current task.

Why ,24 ?
in New Picture…

Try ,32 (no, this is not a joke).

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. :wink:

Windows 10/ Xojo 2017r3

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 sample–p–p (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

thanks Emile for your interest.

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

Cesar: do you understand that using New Picture(Width, Height, 32) you will not get the alpha channel ?
Just try, it will take some seconds only.

I understand your demonstration. That demonstration may not be pertinent with Xojo.

BTW: take a look at the documentation, they explain how to get an Alpha Channel / convert a Picture to have an Alpha Channel.

Of course, I may be wrong, but I do not feel how (in this case).

Taken from http://documentation.xojo.com/index.php/Picture.HasAlphaChannel

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.

It seems a very intelligent solution I had not seen. I’ll go to work…

If poImage is a picture with alpha channel:

Dim plain_img As New Picture(poImage.Width, poImage.Height,32)
plain_img.Graphics.DrawPicture(poImage,0,0)

then plain_img should not have the alpha channel I think.

Dirk: Cesar said 32 bits have Alpha Channel. :frowning:
I told him to try (I know this works and I tested it).

Edit: Read his answer far above.

[quote=386613:@Emile Schwarz]Dirk: Cesar said 32 bits have Alpha Channel. :frowning:
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.

Basically this is what needs to be done http://www.fpdf.org/en/script/script83.php

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.

https://forums.adobe.com/thread/1339523

I spent many weeks getting this to work with gPDF… but it does, and does it well now.

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… :wink:

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.

Further documentation:

https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf
(chapter 7 transparency)

And last but not least, I’ve uploaded my version of rsfpdf to github, which supports the use of transparent PNG’s

I have quickly tested the uploaded version on Mac and Windows, and it seems to work for me.

We use an adapted version of these methods in our main software product and they seem to do the job.
I hope this helps.

Firing the shared project gaves the answer about transparency