1
我正在使用PDF盒子來創建PDF,我正在嘗試將圖片打印成pdf,它的工作原理除PNG以外的所有格式。 mycode的如下:PDF盒子不支持PNG圖片
String image = "c:/image.png";
PDXObjectImage ximage = null;
if(image.toLowerCase().endsWith(".jpg"))
{
ximage = new PDJpeg(doc, new FileInputStream(image));
}
else if (image.toLowerCase().endsWith(".tif") || image.toLowerCase().endsWith(".tiff"))
{
ximage = new PDCcitt(doc, new RandomAccessFile(new File(image),"r"));
}
else
{
BufferedImage awtImage = ImageIO.read(new File(image));
ximage = new PDPixelMap(doc, awtImage);
throw new IOException("Image type not supported:" + image);
}
PDPageContentStream contentStream = new PDPageContentStream(doc, page);
contentStream.drawImage(ximage, 20, 20);
當過我給png圖片是要去:
else
{
BufferedImage awtImage = ImageIO.read(new File(image));
ximage = new PDPixelMap(doc, awtImage);
//throw new IOException("Image type not supported:" + image);
}
,並顯示圖像流的IO異常讀取傾斜的圖像文件。我還需要做些什麼改變來接受png圖像呢?請幫助...
由於以「.png」結尾的文件名將轉到您的「else」塊,並且您的else塊始終會執行一個'throw new IOException(「Image type not supported:」+ image );'作爲第三個語句(不知道爲什麼你有兩個語句之前,如果你打算在每種情況下拋出異常) – 2014-10-06 04:54:48
嗯我忘了刪除,現在刪除 – androidGenX 2014-10-06 05:09:02
@ Erwin Bolwidt顯示圖像流IO異常不能閱讀圖像文件! – androidGenX 2014-10-06 05:10:48