iTextSharp的:如何调整图像大小以适合修复大小? [英] iTextSharp: How to resize an image to fit a fix size?

查看:2591
本文介绍了iTextSharp的:如何调整图像大小以适合修复大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将图像调整到159X159点的尺寸,使用iTextSharp的4.2.0,但产生的图像需要有特定的尺寸准确。

I want to be able to resize an image to the dimension of 159x159 points, using iTextSharp 4.2.0, but the resulting image need to have exactly the dimensions specified.

我试过这样:

Image image = Image.GetInstance(imagePath);
image.ScaleAbsolute(159f, 159f);



但图像不是正方形。
我有这样的形象:

But the image is not a square. It keeps the aspect ratio.

Example: I have this image:

例=htt​​p://i.stack.imgur.com/Qs0ZV.pngALT =在这里输入的形象描述>

和结果的图像看起来应该这个魔神

And the result image should look loke this:

感谢。

推荐答案

您所描述的问题通常是,当你尝试会发生什么添加一个图片直接将 PdfPTable 致电 AddCell(),其中总是缩放图像以适合 PdfPCell 。所以,如果您要添加图像到文件是这样的:

The problem you describe is typically what happens when you try and add an Image directly to a PdfPTable by calling AddCell(), which always scales the image to fit the PdfPCell. So if you're adding the image to the Document like this:

Image img = Image.GetInstance(imagePath);
img.ScaleAbsolute(159f, 159f);
PdfPTable table = new PdfPTable(1);
table.AddCell(img);
document.Add(table);

ScaleAbsolute()通话将被忽略。要获得扩展你想要的:

your ScaleAbsolute() call is ignored. To get the scaling you want:

PdfPTable table = new PdfPTable(1);
table.AddCell(new PdfPCell(img));
document.Add(table);

这篇关于iTextSharp的:如何调整图像大小以适合修复大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆