__BlueCat
2019-06-13 19:54
采纳率: 75%
浏览 633
已采纳

怎么把BufferedImage转成tiff格式的图片

怎么把BufferedImage转成tiff格式的图片 求代码

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • __BlueCat 2019-06-24 17:44
    已采纳

    为什么又要我自己答....
    用到的包:pdfbox和开源icafe

     File sourceFile = new File(emailSavePath + "//" + fileName);
            PDDocument doc = PDDocument.load(sourceFile);
            PDFRenderer renderer = new PDFRenderer(doc);
            int pageCount = doc.getNumberOfPages();
            BufferedImage[] images = new BufferedImage[pageCount];
            for (int i = 0; i < pageCount; ++i) {
                BufferedImage image = renderer.renderImageWithDPI(i, 150, ImageType.GRAY);
                images[i] = image;
            }
    
            FileOutputStream fos = new FileOutputStream(emailSavePath + "\\" + targetFile);
    
            RandomAccessOutputStream rout = new FileCacheRandomAccessOutputStream(fos);
            ImageParam.ImageParamBuilder builder = ImageParam.getBuilder();
            ImageParam[] param = new ImageParam[1];
            TIFFOptions tiffOptions = new TIFFOptions();
            tiffOptions.setTiffCompression(Compression.JPG);
            tiffOptions.setJPEGQuality(60);
            /*
             * tiffOptions.setXResolution(200); tiffOptions.setYResolution(200);
             */
            builder.imageOptions(tiffOptions);
            builder.colorType(ImageColorType.GRAY_SCALE);
            // builder.bitsPerPixel(1);
            param[0] = builder.build();
            TIFFTweaker.writeMultipageTIFF(rout, param, images);
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题