Looking for Image2RGBA or Image2CMYKA to load images with alpha channel

I’m using Image2RGB to convert image from CMYK to RGB.

It works but images with alpha on background lost the backgorund alpha with black.

I saw that on old pdfnet library there was the class Image2RGBA but it seems deprecated. I’m using last version of PDFNet and I can’t find it on library.

This is the code:

pdftron.PDF.Image img = new pdftron.PDF.Image(e.GetXObject());

pdftron.PDF.Image2RGB rgb = new Image2RGB(img);

FilterReader filterReader = new FilterReader(rgb);

byte[] data = new byte[img.GetImageDataSize()];

filterReader.Read(data);

pdftron.PDF.Image img_rgb = pdftron.PDF.Image.Create(doc, data, img.GetImageWidth(), img.GetImageHeight(), 8, ColorSpace.CreateDeviceRGB());

GState gs = e.GetGState();

pdftron.Common.Matrix2D m2d = gs.GetTransform();

Element eNew = builder.CreateImage(img_rgb, m2d);

writer.WritePlacedElement(eNew);

doc.GetSDFDoc().Swap(img.GetSDFObj().GetObjNum(), img_rgb.GetSDFObj().GetObjNum());

A:

In PDF the alpha channel is stored separately from the base image. The so called ‘image’ or ‘soft’ mask may not be of the same dimensions as the base image so Image2RGBA filer would not make sense (which is why it was deprecated).

You can obtain the ‘image’ or ‘soft’ mask using Image.GetSoftMask() or Image.GetMask() then you can use Image2RGB() or extract raw image data (since it is just a gray channel).

For more info please see:

https://groups.google.com/d/topic/pdfnet-sdk/AZC3_RjiLn4/discussion

https://groups.google.com/d/topic/pdfnet-sdk/pd2mryv-CGE/discussion