English 中文(简体)
阅读和书写在 Java的森林论坛形象
原标题:Reading and Writing out TIFF image in Java
  • 时间:2010-05-24 16:02:12
  •  标签:
  • java
  • tiff

我尝试了以下法典,以完成阅读和书写 t图像的任务:

 // Define the source and destination file names.
 String inputFile = /images/FarmHouse.tif
 String outputFile = /images/FarmHouse.bmp

 // Load the input image.
 RenderedOp src = JAI.create("fileload", inputFile);

 // Encode the file as a BMP image.
 FileOutputStream stream =
     new FileOutputStream(outputFile);
 JAI.create("encode", src, stream, BMP, null);

 // Store the image in the BMP format.
 JAI.create("filestore", src, outputFile, BMP, null);

然而,在我管理守则时,我收到以下错误信息:

Caused by: java.lang.IllegalArgumentException: Only images with either 1 or 3 bands 
can be written out as BMP files.
 at com.sun.media.jai.codecimpl.BMPImageEncoder.encode(BMPImageEncoder.java:123)
 at com.sun.media.jai.opimage.EncodeRIF.create(EncodeRIF.java:79)

我如何解决这一问题的想法?

最佳回答

政府间森林论坛和发展局产出中最容易阅读的办法是使用图象分类:

BufferedImage image = ImageIO.read(inputFile);
ImageIO.write(image, "bmp", new File(outputFile));

你需要做的唯一额外工作是,确保你将JAI图像I JAR列入你的班子,因为博爱委员会和政府间森林论坛没有来自该图书馆的原始资料就没有处理。

如果你可以出于某种原因使用JAI图像IO,那么你就可以与你现有的法典合作,但你不得不做一些额外的工作。 正在为森林论坛设计的、你正在装货的彩色模型可能是没有BMP支持的指数化彩色模型。 您可以代之以JAI.create(“format”)......的运作,提供与JAI.KEY_REPLACE_INDEX_COLOR_MODEL的钥匙相配套。

你们也许会用一些uck子书写从档案中读到临时形象的形象,然后写出温像:

BufferedImage image = ImageIO.read(inputFile);
BufferedImage convertedImage = new BufferedImage(image.getWidth(), 
    image.getHeight(), BufferedImage.TYPE_INT_RGB);
convertedImage.createGraphics().drawRenderedImage(image, null);
ImageIO.write(convertedImage, "bmp", new File(outputFile));

我很想知道,你是否重新进入与常设联合审计团相同的指数色模型问题。 理想的情况是,你应利用图像和图像分类,为除最简单情况外的所有人提供图像检索和图像,以便你能够相应地打上阅读和书写字节,但图像和图像组织(StuIO)和(write)可以被罚款给你想要的东西。

问题回答
FileInputStream in = new FileInputStream(imgFullPath);
FileChannel channel = in.getChannel();
ByteBuffer buffer = ByteBuffer.allocate((int)channel.size());
channel.read(buffer);
tiffEncodedImg = Base64.encode(buffer.array()); 

将“tiffEncodedImg”这一内容(即“tiffEncodedImg”的价值)作为超文本标记的弧值





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签