Skip to main content

Convert JPEG/Gif to Tiff

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
pedro_riky
Offline
Joined: 2008-11-06

Hi all i try to convert images, in many format in tiff format.

The byte array is the image, previously saved in a oracle blob.

<br />
public static byte[] convertByte2TIFF(byte[] bytes) {<br />
		ByteArrayInputStream bis = new ByteArrayInputStream(bytes);<br />
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();</p>
<p>		SeekableStream s = SeekableStream.wrapInputStream(bis, true);</p>
<p>		RenderedOp image = JAI.create("stream", s);</p>
<p>		((OpImage) image.getRendering()).setTileCache(null);</p>
<p>		ParameterBlock pb = new ParameterBlock();<br />
		pb.addSource(image); // The source image<br />
		pb.add(1.0F); // The xScale<br />
		pb.add(1.0F); // The yScale<br />
		pb.add(0.0F); // The x translation<br />
		pb.add(0.0F); // The y translation<br />
		pb.add(new InterpolationNearest()); // The interpolation</p>
<p>		RenderedOp resizedImage = JAI.create("scale", pb, null);<br />
		// converting all files to tiff format<br />
		RenderedOp op = JAI.create("encode", resizedImage, outputStream,<br />
			"TIFF", null);</p>
<p>		// converting tiff format to bytes<br />
		byte[] imgBytes = outputStream.toByteArray();</p>
<p>		try {<br />
			outputStream.close();<br />
			s.close();<br />
			bis.close();<br />
		} catch (IOException e) {<br />
		}<br />
		return imgBytes;<br />
	}<br />

If i try to convert the image i get this exception:

java.lang.RuntimeException: - Unable to render RenderedOp for this operation.

on ((OpImage) image.getRendering()).setTileCache(null);
and on RenderedOp op = JAI.create("encode", resizedImage, outputStream,"TIFF", null);

I use jai_codec-1.1.2_01.jar and jai_core-1.1.2_01.jar

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
susannamoore
Offline
Joined: 2014-03-13