【问题标题】:Rendering an image on a PDF page在 PDF 页面上渲染图像
【发布时间】:2014-09-18 08:42:43
【问题描述】:

我正在尝试在 PDF 页面中创建和呈现图像。我正在使用PDEImageCreate API 创建一个PDEImage 对象,然后将此对象设置在PDEContentPDPage 中。

但是,我无法在页面上呈现正确的图像。我发送原始数据作为输入并使用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 会抛出错误消息。

我确信我错过了一些重要的事情。有人能指出我正确的方向吗?

【问题讨论】:

  • 为什么图像是蒙版?如果没有例外,也许图像很好,但错误与您定义 PDF 的其余部分有关。例如,XObject 图像需要使用 Do 操作符进行渲染。

标签: c++ image pdf


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 2013-07-31
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多