How do I invert colors when extracting an embedded PDF image?

Q:

I need to extract some tif images from a PDF files with your library,
when i extract this PDF, the tif file appears with black and white
reverse. It works well with color tif.

                PDFNet.Initialize();
                PDFDoc one_pdf = new PDFDoc(tb_pdf.Text);
                PageIterator page_end = one_pdf.PageEnd();
                PageIterator page_begin = one_pdf.PageBegin();
                ElementReader pdfreader = new ElementReader();
                PageIterator itr,itr2;
    for (itr = page_begin; itr != page_end; itr.Next())
                {
                    pdfreader.Begin(itr.Current());
                    Element pdfelement;
                    while ((pdfelement = pdfreader.Next()) != null)
                    {
                        switch (pdfelement.GetType())
                        {
                             case Element.Type.e_image:
                             {
                                   string fname = [my_output files
path] + image_counter;
                                  pdftron.PDF.Image image = new
pdftron.PDF.Image(pdfelement.GetXObject());
                                   image.ExportAsTiff(fname+".tif");
                                   image_counter++;
                                   break;
                             }
                        }
                    }
                    pdfreader.End();
                }
                one_pdf.Close();
                PDFNet.Terminate();
-------
A:

Regarding the problem of inverted tiff, you could set Decode array
just before exporting the TIF. For example,

//-------------------------
pdftron.PDF.Image image = new
pdftron.PDF.Image(pdfelement.GetXObject());

pdftron.SDF.Obj dec = Obj.CreateArray();
// Invert the following two lines to invert the color in the output
TIFF
dec.PushBack(Obj.CreateNumber(1));
dec.PushBack(Obj.CreateNumber(0));
image.GetSDFObj().Put("Decode", dec);

image.ExportAsTiff("my.tif");

... erase Decode from image dictionary ?
//-------------------------

Please keep in mind that the number of entries in the decode array
should be two times of the number of color components in the image
color space (so the above code assumes that the image is monochrome or
grayscale). This way it is possible to invert (or adjust) each color
channel separately.