如何使用Mako SDK在文档的页面的给定区域内平铺图像?

问题描述 投票:1回答:1

我希望在我的文档中使用图像来填充,填充和覆盖我的页面区域。

我已经看到有一个IDOMImageIDOMImageBrush,但我不知道如何使用它们来缩放和平铺我的源图像。

如何使用Mako SDK完成此操作?

c++ pdf xps mako-sdk
1个回答
2
投票

Mako可以将图像平铺到给定区域,还可以翻转替代图块以创建图案。使用缩放变换来控制其大小。这段代码告诉你如何。

// Declare an output pointer
IOutputPtr output;

// Create new assembly, document and page
IDocumentAssemblyPtr assembly = IDocumentAssembly::create(jawsMako);
IDocumentPtr document = IDocument::create(jawsMako);
IPagePtr page = IPage::create(jawsMako);

// Add the page to the document, and the document to the assembly
document->appendPage(page);
assembly->appendDocument(document);

// Create a fixed page to work with
double pageWidth = 10 * 96.0;
double pageHeight = 20 * 96.0;
IDOMFixedPagePtr fixedPage = IDOMFixedPage::create(jawsMako, pageWidth, pageHeight);

// Load the image file into an image
IDOMImagePtr image = IDOMJPEGImage::create(jawsMako, IInputStream::createFromFile(jawsMako, imageFilePath));

// Find its dimensions
IImageFramePtr frame;
image->getFirstImageFrame(jawsMako, frame);
double imageWidth = frame->getWidth();
double imageHeight = frame->getHeight();

// Create a rect to hold the image
FRect printBounds(0.0, 0.0, pageWidth, pageHeight);

// Create a transformation matrix to scale the image, taking into account the page proportions
// Scaling factor is a float ranging from 0.0 to 1.0
double pageWidthHeightRatio = pageWidth / pageHeight;
FMatrix transform;
transform.scale(scalingFactor, scalingFactor * pageWidthHeightRatio);

// Stick the image in a brush
IDOMBrushPtr imageBrush = IDOMImageBrush::create(jawsMako, image, FRect(), printBounds, transform, 1.0, eFlipXY);

// And now create a path using the image brush
IDOMPathNodePtr path = IDOMPathNode::createFilled(jawsMako, IDOMPathGeometry::create(jawsMako, printBounds), imageBrush);

// Add the path to the fixed page
fixedPage->appendChild(path);

// This becomes the page contents
page->setContent(fixedPage);

// Write to the output
output = IPDFOutput::create(jawsMako);
output->writeAssembly(assembly, outputFilePath);

使用此代码,使用此图像:

Original Image

制作这个耕种的图像:

Tiled Image

该代码使用枚举,eTileXY。这些是可用的平铺选项:

eTilingMode Tiling模式类型枚举。

eNoTile 没有平铺。如果要绘制的区域大于图像,只需绘制一次图像(在画笔视口指定的位置),并使剩余区域保持透明。

eTile 无需翻转或旋转图像即可平铺图像。在这种模式下平铺时,由相对角之间的单个对角线组成的正方形图像将产生对角线。

eFlipX 平铺图像使得交替的瓷砖列水平翻转。在这种模式下平铺时,由相对角之间的单个对角线组成的正方形图像将产生在该区域上水平延伸的V形纹。

eFlipY 平铺图像使得交替的瓷砖行垂直翻转。在这种模式下平铺时,由相对角之间的单个对角线组成的方形图像将产生垂直穿过该区域的V形图案。

eFlipXY 平铺图像使得交替的瓦片列水平翻转并且交替的瓦片行垂直翻转。在这种模式下平铺时,由相对角之间的单个对角线组成的正方形图像将产生在其点上平衡的正方形网格。

© www.soinside.com 2019 - 2024. All rights reserved.