I am trying to render a Tiff Image for extracting tags from it, here is what i have done till now:
我试图渲染一个Tiff图像从中提取标签,这是我迄今为止所做的:
ByteArraySeekableStream sStream= new ByteArraySeekableStream(imageByteArray);
ImageDecoder imgDecoder = ImageCodec.createImageDecoder("TIFF",sStream,null);
RenderedImage renderedImage = imgDecoder.decodeAsRenderedImage();
this seems to work fine for all positive scenarios, where as suppose if we have a TIFF image which has a missing tag in it.
这似乎适用于所有积极的场景,假设我们有一个TIFF图像,其中有一个缺少的标签。
for eg: If Image Length is missing, then i get the following exception:
例如:如果缺少图像长度,则会出现以下异常:
java.io.IOException: "Image Length", a required field, is not present in the TIFF file
but i do not want it to throw any exception, rather it should render the image with whatever TIFF tags are present.
但我不希望它抛出任何异常,而是应该使用任何TIFF标签呈现图像。
Is there any other way of rendering a TIFF image? or is there a way of modifying the above code to achieve this requirement.
还有其他渲染TIFF图像的方法吗?或者有没有办法修改上面的代码来达到这个要求。
1 个解决方案
#1
1
To get the Tiff tags, u don't need to render the image first. If you render the image you will definitely get that exception if any tags are not proper.
要获取Tiff标签,您不需要先渲染图像。如果渲染图像,如果任何标记不正确,您肯定会得到该异常。
Instead try this,
相反,试试这个,
ByteArraySeekableStream sStream= new ByteArraySeekableStream(imageByteArray);
And get the Tiff directory from the stream instead of rendered image
并从流中获取Tiff目录而不是渲染图像
TIFFDirectory tiffDr = new TIFFDirectory(sStream, 0)
From this you can get the Tiff tags, and then do the validations on the available tags in the image. Hope this helps.
从这里你可以得到Tiff标签,然后对图像中的可用标签进行验证。希望这可以帮助。
#1
1
To get the Tiff tags, u don't need to render the image first. If you render the image you will definitely get that exception if any tags are not proper.
要获取Tiff标签,您不需要先渲染图像。如果渲染图像,如果任何标记不正确,您肯定会得到该异常。
Instead try this,
相反,试试这个,
ByteArraySeekableStream sStream= new ByteArraySeekableStream(imageByteArray);
And get the Tiff directory from the stream instead of rendered image
并从流中获取Tiff目录而不是渲染图像
TIFFDirectory tiffDr = new TIFFDirectory(sStream, 0)
From this you can get the Tiff tags, and then do the validations on the available tags in the image. Hope this helps.
从这里你可以得到Tiff标签,然后对图像中的可用标签进行验证。希望这可以帮助。