在PDF页面上呈现图像

Rendering an image on a PDF page

本文关键字:图像 PDF      更新时间:2023-10-16

我正在尝试创建和渲染PDF页面中的图像。我使用PDEImageCreate API来创建一个PDEImage对象,然后在PDPagePDEContent中设置这个对象。

但是,我无法在页面上呈现正确的图像。我正在发送原始数据作为输入并使用DeviceRGB颜色空间。下面是我使用的代码的快照:

unsigned char* mImageDataBuffer;    
mImageDataBuffer = (unsigned char*)ASmalloc((ASSize_t)30000);
imageAttrs.bitsPerComponent = 8;
imageAttrs.flags = kPDEImageIsMask;
imageAttrs.width = 100;
imageAttrs.height = 100;
imageAttrs.intent = ASAtomNull;
imageMatrix.a = ASFloatToFixed(500.0);
imageMatrix.b = fixedZero;
imageMatrix.c = fixedZero;
imageMatrix.d = ASFloatToFixed(500.0);
imageMatrix.h = fixedZero;
imageMatrix.v = fixedZero;
for (int i = 0; i < 30000;)
{
    mImageDataBuffer[i++] = 0x00;
    mImageDataBuffer[i++] = 0x00;
    mImageDataBuffer[i++] = 0x0f;
}
PDEColorValueP pdeColorValue = (PDEColorValueP)ASmalloc(sizeof(PDEColorValue));
memset(pdeColorValue, 0, sizeof(PDEColorValue));
pdeColorValue->color[0] = FloatToASFixed(255.0f);
pdeColorValue->color[1] = FloatToASFixed(0.0f);
pdeColorValue->color[2] = FloatToASFixed(0.0f);
pdeImage = PDEImageCreate(&imageAttrs, (Uns32)sizeof(imageAttrs), &imageMatrix, 0, PDEColorSpaceCreateFromName(ASAtomFromString("DeviceRGB")),
    pdeColorValue, NULL, 0, mImageDataBuffer, 0);

主要有两个问题我无法找出原因——

  1. 我尝试在mimagedatbuffer中放置随机值,如果在页面上渲染任何东西,它总是黑色和白色。

  2. 如果数据缓冲区的一个字节是0x00,那么如果其余字节非零,Acrobat将抛出错误消息。

我肯定我错过了一些重要的东西。有人能告诉我正确的方向吗?

最后一个参数不应该是mImageDataBuffer的大小吗?例如:

pdeImage = PDEImageCreate(&imageAttrs, (Uns32)sizeof(imageAttrs), &imageMatrix, 0,       PDEColorSpaceCreateFromName(ASAtomFromString("DeviceRGB")),
pdeColorValue, NULL, 0, mImageDataBuffer, 30000);