我正在尝试用pdf替换图像,但并非所有图像都已完成

时间:2018-06-15 15:29:54

标签: pdf itext pdfbox

public static Image makeBlackAndWhitePng(PdfImageObject image) throws IOException, DocumentException {
    File f = new File("C:\\Users\\anahata\\Desktop\\text analysis\\14-1.png");
    BufferedImage bi = image.getBufferedImage();
    BufferedImage x = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);
    x = ImageIO.read(f);
    BufferedImage newBi = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_USHORT_GRAY);
    newBi.getGraphics().drawImage(bi, 0, 0, null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(x, "png", baos);
    return Image.getInstance(baos.toByteArray());
}

0 个答案:

没有答案