/**
* Crop the main image according to this rectangle, and scale it to the
* correct size for a thumbnail.
*/
public InputStream cropAndScale(InputStream mainImageStream,
CropRectangle crop) {
try {
RenderedOp mainImage = loadImage(mainImageStream);
RenderedOp opaqueImage = makeImageOpaque(mainImage);
RenderedOp croppedImage = cropImage(opaqueImage, crop);
RenderedOp scaledImage = scaleImage(croppedImage);
byte[] jpegBytes = encodeAsJpeg(scaledImage);
return new ByteArrayInputStream(jpegBytes);
} catch (Exception e) {
throw new IllegalStateException("Failed to scale the image", e);
}
}
假设您在PDF文件中有乐谱,我将使用Apache PDFBox从包含乐谱的输入PDF文件中获取图像,然后定位所需的整个条的坐标,使用选定的图像定义坐标以裁剪图像并对其进行操作,直到获得所需的结果。在
下面是apachepdfbox中提供的示例代码。在
^{pr2}$现在要裁剪图像,您可以使用:
它在this page和project中可用
还有一个选项可以解析pdf文件中的图像,请看一下at this code特别是this
相关问题 更多 >
编程相关推荐