How do I specify transparent color in an image (a.k.a. color-key masking)?

Q: I am working on importing a pdf and adding a background layer to
that page. I can get the background layer added, but there is an image
in the foreground that has a white square around it. I have seen that
I need to add a mask to the image.

In the past I have been able to use this:

Image mask = Image.Create(doc, newFilename);
      mask.GetSDFObj().PutBool("ImageMask", true);
      mask.GetSDFObj().Erase("ColorSpace");

      image.SetMask(mask);

But for this pdf I don't have the image saved to create a mask from. I
have seen that I can use SetMask and pass in an array to the element,
but I can't find any examples on how to choose the color to remove.
How would I setup a mask to make the white transparent?
---------------
A: The simplest approach would be to specify alpha transparency as
part of the input image. PDFNet will automatically recognize the alpha
channel and will preserve this info as a soft mask.

If this does not work you could try to use color-key masking (section
8.9.6.4 ‘Colour Key Masking’ in PDF Reference): For example:

Obj mask = image.GetSDFObj().PutArray("Mask");
// Assuming RGB color space...
mask.PushBackNumber(254); mask.PushBackNumber(255);
mask.PushBackNumber(254); mask.PushBackNumber(255);
mask.PushBackNumber(254); mask.PushBackNumber(255);

From the reference:

For colour key masking, the value of the Mask entry shall be an array
of 2^n integers,
[ min1 max1 … minn maxn ], where n is the number of colour components
in the image’s colour space. Each integer shall be in the range 0 to
2^BitsPerComponent - 1, representing colour values before decoding
with the Decode array. An image sample shall be masked (not painted)
if all of its colour components before decoding, c1 … cn , fall within
the specified ranges (that is, if mini £ ci £ maxi for all 1 £ i £ n).