[C/C++] Embedding a raw RGB, CMYK image

Q: I am having a problem with outputting an built-in bitmap to PDF.

With the code extract below I getting an image of the correct size and
correct position but the image coming out is incorrect

  SECDib SECImage;
  CWinApp* app = ::AfxGetApp();
  CWindowDC dc(app->m_pMainWnd);
  CDib *Dib=Bmap->GetDib();
  CPalette *OldPal=dc.SelectPalette(SECImage.m_pPalette,FALSE);

  SECImage.FlipVert(); // Y axis is upsidedown
  Image PDFImage=Image::Create(*m_PDFDoc,(char




  ElementBuilder Builder;

  Matrix2D ImageMatrix(CX,0,0,CY,PX,PY);
  if (rotation!=CAngle(0))
  Element *Element=Builder.CreateImage(PDFImage,ImageMatrix);


If I replace the bits per colour with 8 I get an image with only an
1/8th of the filling, if I replace RGB with CMYK the image looks
correct but with incorrect colours.

I feel that I am close but just missing something!
A: It seems that you would like to embed RAW RGB image data using
Image::Create method.

The first question is what is the memory layout of the input RGB
image. Is SECDib using a palletized image? Image::Create does not
accept palletized images, so you may need to convert the image to RGA
format. Second your BPC (Bits Per Component) parameter is set to 1.
This means that you are embedding a monochrome image, RGB images can't
be embedded as monochrome (i.e. BPC should be set to 8 - in most
cases). In case you would like to embed CMYK data you need to pass
CMYK color space to Image::Create (so instead of
ColorSpace::CreateDeviceRGB() pass in ColorSpace::CreateDeviceCMYK()).
Third, the image size (in bytes) is ( BitmapInfo-

bmiHeader.biWidth*BitmapInfo->bmiHeader.biHeight * 3) for RGB and

(BitmapInfo->bmiHeader.biWidth*BitmapInfo->bmiHeader.biHeight * 4) for
CYK images.