本文介绍了在Java eclipse中阅读Tiff格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我如何使用Java IMAGEIO库读取TIFF图像?(我正在使用Eclipse Luna)..而且一旦我下载插件(JAR文件)如何给Classpath以便它可以读取我的输入TIFF图像文件?How do i read a TIFF image using Java IMAGEIO library??(I am using Eclipse Luna)..And once i download the plugin(JAR files) how to give the Classpath so that it can read my input TIFF image file?推荐答案这是一个将TIFF图像转换为PNG图像的快速示例。Here a quick example to convert a TIFF image into a PNG image.// quick conversion exampleFile inputFile = new File("image.tiff");File outputFile = new File("output.png");BufferedImage image = ImageIO.read(inputFile);ImageIO.write(image, "png", outputFile);打印JAI ImageIO库所有支持格式的列表。Print a list of all supported formats of the JAI ImageIO library.import javax.imageio.ImageIO;...for (String format : ImageIO.getWriterFormatNames()) { System.out.println("format = " + format);} 注意对于转换包含的图片格式没有内置支持,支持库必须在类路径中。要查找支持的格式,请查看 https://docs.oracle.com/ javase / tutorial / 2d / images / loadimage.html 或上面的代码段。 note For the convertion of image formats which have no built-in support a supporting library must be in the classpath. To find the supported formats check https://docs.oracle.com/javase/tutorial/2d/images/loadimage.html or the snippet above. 例如。对于TIFF,您可以使用 jai_imageio-1.1.jar (或 newer )。e.g. for TIFF you could use the jai_imageio-1.1.jar (or newer).javac -cp jai_imageio-1.1.jar:. Main.javajava -cp jai_imageio-1.1.jar:. Main如果类路径中没有TIFF格式支持库,则上述转换代码段失败并带有 java.lang.IllegalArgumentException:image == null!。If no TIFF format supporting library is in the classpath the above convertion snippet fails with java.lang.IllegalArgumentException: image == null!.以下格式具有内置支持(Java 8)Following formats have built-in support (Java 8)BMPGIFJPEGPNGWBMP jai_imageio-1.1.jar 增加对JPEG2000PNMRAWTIFF 编辑随着时间的推移和Java 9的发布,这是一个小小的更新,因为Java 9现在支持TIFF。edit As times goes by and Java 9 is released, a small update, because Java 9 supports TIFF now out of the box.使用Java 9编译并运行,无需额外的库compile and run with Java 9 without an additional libraryimport java.awt.image.BufferedImage;import java.io.File;import javax.imageio.ImageIO;class TiffToPng { public static void main(String[] args) throws Exception { File inputFile = new File("image.tiff"); File outputFile = new File("output.png"); BufferedImage image = ImageIO.read(inputFile); ImageIO.write(image, "png", outputFile); }}查找支持 ImageReader / ImageWriter 格式。您可以在片段后使用的MIME类型to find supported ImageReader / ImageWriter formats resp. MIME types you could use following snippetsfor (String format : ImageIO.getReaderFormatNames()) { System.out.println("format = " + format);}...for (String format : ImageIO.getReaderMIMETypes()) { System.out.println("format = " + format);}for (String format : ImageIO.getWriterFormatNames()) { System.out.println("format = " + format);}...for (String format : ImageIO.getWriterMIMETypes()) { System.out.println("format = " + format);} 这篇关于在Java eclipse中阅读Tiff格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 10:24