I'm a little late to answer, I think, but here is the real answer.
I have successfully added itk :: Image to my pdf using LibHaru, so it should work about the same for you. First, you need to know if the library you are using is a row or column. LibHaru (and all the libraries that I know) works in strings, so your library should also be, or you will have to "transpose" your data.
// Black and white image (8 bits per pixel) itk::Image<unsigned char, 2>::Pointer image = ...; const unsigned char *imageData = image->GetBufferPointer(); const HPDF_Image image = HPDF_LoadRawImageFromMem(m_Document, imageData, width, height, HPDF_CS_DEVICE_GRAY, 8); // Or color image (24 bits per pixel, 8 bits per color component) itk::Image<RGBPixel, 2>::Pointer image = ...; const RGBPixel *imageData = image->GetBufferPointer(); const HPDF_Image image = HPDF_LoadRawImageFromMem(m_Document, reinterpret_cast<const unsigned char *>(imageData), width, height, HPDF_CS_DEVICE_RGB, 8); // Usual LibHaru code. EndText, Position, Draw, StartText, etc. // This code should not be dependant on the type InsertImage(image);
I think the only tricky part is reinterpret_cast. A black and white image is not needed because it is already defined as a byte. For example, if you have this image
102 255 255 99 200 0 255 0 100 imageData == {102, 255, 255, 99, 200, 0, 255, 0, 100};
However, if you have this color image
( 0, 0, 255) (0, 255, 255) ( 42, 255, 242) (200, 200, 255) (0, 199, 199) (190, 190, 190) imageData == {0, 0, 255, 0, 255, 255, 42, 255, 242, 200, 200, 255, ... }
which LibHaru will endure because you tell it to use HPDF_CS_DEVICE_RGB, which means that it will group the data into (R, G, B).
Of course, using ImageMagick, you need to find how to access the first pixel. This is probably a method, e.g. data (), begin (), pointer (), etc.