Why do I get different colors after my PDF image optimization and processing?

Q: I am trying to make a tool to compress all images within a pdf to
jpeg images.
The problem I've encountered is that the images colors change ,this is
my code:

       static ObjSet hint_set = null;
       static Obj jp2_hint = null;
        PDF::Image image(obj);

        if(image.GetComponentNum() == 1)

        Image2RGB img_conv(image);// createing image data from input
        FilterReader reader1(img_conv);

        if (jp2_hint == null) {
          hint_set=new ObjSet();
          jp2_hint = hint_set.CreateArray();

        Image new_image = Image::Create(cos_doc, reader1,
        image.GetImageHeight(), image.GetBitsPerComponent(),
ColorSpace::CreateDeviceRGB(), jp2_hint);// creating the new image

        Obj new_img_obj = new_image.GetSDFObj();
        obj.GetDoc().Swap(obj.GetObjNum(), new_img_obj.GetObjNum
()); // swaping the old image object with the new compressed image

The problem is that some colors in recompressed images are quite
different from original images. My question is why the images have
different colors and how can I prevent this from happening?

A: The problem is that you are normalizing all images to RGB (using
Image2RGB). This means that you may need to convert images from CMYK,
DeviceN, ... etc to RGB which is a lossy process.

You will be able to get better results if you enable color management
(plese see http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/3c6601a5a4c0f72c/c305d72956ffadcb;
or "How do I enable ICC color management in PDFNet?").

Also a good news is that upcoming version of PDFNet will feature
further improvements in ICC color support including more control for
color tweaking in advanced color workflows.

Another note regarding image compression. You will be able to achieve
more significant compression by down-sampling (i.e. decreasing the
image resolution) on images If you are developing under .NET, you
could use GDI+ API to shrink down System.Drawing.Bitmap (you may want
to use bmp.GetThumbnailImage (). If this doesn't work as expected you
can alternatively create a new smaller System.Drawing.Bitmap, create a
new Drawing surface and attach it to the Bitmap, draw from the
original input bitmap to the smaller bitmap, then embed the resulting
Bitmap in PDF using pdftron.PDF.Image.Create (bmp)).