pdfGetImageBitmap

Get an in-memory bitmap for an image.
// Windows int pdfGetImageBitmap(PDFHandle pdf, int idx, BITMAPINFOHEADER *dibHdr, char **bits) // Linux, Mac OS X int pdfGetImageBitmap(PDFHandle pdf, int idx, PDFImageHeader *imgHdr, char **bits)
This function extracts a bitmap to memory for the idxth image on the page specified in the last call to pdfGetImages.

In the Windows version of XpdfImageExtract, this function fills in a BITMAPINFOHEADER structure. In the Linux and Mac versions, it fills in a PDFImageHeader structure defined in XpdfImageExtract.h. In either case, the second argument is the image index (same as for pdfGetImageInfo), the third argument is a pointer to the image header structure (BITMAPINFOHEADER or PDFImageHeader, and the fourth argument is a pointer to the image bitmap data.

For image masks and monochrome images, this function creates a one-bit-deep bitmap. For grayscale images, it creates an 8-bit grayscale bitmap. All color images are converted to 24-bit RGB.

On Windows: The data returned in bits is stored in bottom-up (upside-down) format, with each line padded to a multiple of 32 bits (standard Windows bitmap format).

On Linux and Mac: For image masks and monochrome images, the hdr.color flag is set to pdfImageExtractMono, and the data returned in bits is one bit per pixel. For grayscale images, the hdr.color flag is set to pdfImageExtractGray, and the bits data is 8 bits per pixel. For color images, hdr.color is set to pdfImageExtractRGB, and the bits data is 24 bits per pixel (R, G, B order). The lines are stored in top-down format, and for monochrome images each line starts at a byte boundary.

The caller is responsible for calling pdfFreeMemory to free the bits pointer after using it.

C:
#ifdef _WIN32 BITMAPINFOHEADER hdr; #else PDFImageHeader hdr; #endif char *bits; int nImgs, i; pdfGetImages(pdf, 1); nImgs = pdfGetNumImages(pdf); for (i = 0; i < nImgs; ++i) { pdfGetImageBitmap(pdf, i, &hdr, &bits); ... pdfFreeMemory(bits); }
pdfGetImages
pdfGetNumImages
pdfFreeMemory