2014-07-26 125 views
2

我正尝试在PDF页面中创建并呈现图像。我正在使用PDEImageCreate API创建一个PDEImage对象,并稍后在PDPagePDEContent中设置此对象。在PDF页面上呈现图像

但是,我无法在页面上呈现正确的图像。我将原始数据作为输入并使用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. 我试图把随机值在mImageDataBuffer如果任何东西都呈现在页面上,它总是黑白的。

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

我确定我错过了一些重要的东西。有人能指引我走向正确的方向吗?

+2

为什么图像是一个蒙版?如果没有例外,那么图像可能没问题,但是如何定义PDF的其余部分会出现错误。例如,XObject图像需要使用Do操作符来渲染。 –

回答

0

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

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