在Itext中裁剪图像 [英] Cropping images in Itext

查看:144
本文介绍了在Itext中裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种简单的方法可以在Itext中裁剪图像吗?

is there an easy way to crop an Image in Itext?

我有以下代码:

URL url = new URL(imgUrl);

connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
iStream = connection.getInputStream();
img = new Jpeg(url);

// a method like 
// img.crop(x1, y1, x2, y2) would be nice.

现在我想删除一条左边的像素,左边20像素,右边20像素。
有没有一种简单的方法可以做到这一点?

Now I want to "delete" a strip of let's say 20 pixels left and 20 pixels right. Is there an easy way to do this?

推荐答案

您可以使用剪切路径进行调查。您需要知道JPEG的宽度和高度。代码可能如下所示:

You could investigate using the clipping path. You'll need to know the width and height of the JPEG. The code might look something like this:

PdfTemplate t = writer.getDirectContent().createTemplate(850, 600);
t.rectangle(x+20,y+20, width-40, height-40);
t.clip();
t.newPath();
t.addImage(img, width, 0, 0, height, x, y);

这篇关于在Itext中裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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