I'm trying to read in a blob, convert it to JPG and then write back to the blob (it is being passed in by reference, but when trying to compile in TOAD I get an error on ImageIO.write.
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED BANNADMIN.IMAGE_CONVERTER
AS package uk.co.ImageUtil;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import oracle.sql.*;
import java.io.OutputStream;
public class ImageConverter {
public static void convertImage(BLOB[] blob) {
BufferedImage image = null;
OutputStream outputStream = null;
try {
image = ImageIO.read(blob[0].getBinaryStream());
outputStream = blob[0].setBinaryStream(0);
ImageIO.write(image, "JPG", outputStream);
} catch (IOException e) {
e.printStackTrace();
}
catch (SQLException e) {
e.printStackTrace();
}
catch(IllegalArgumentException e) {
e.printStackTrace();
}
finally {
try {
if (outputStream !== null) {
outputStream.flush();
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/
How would I convert a BufferedImage into a RenderedImage so I can write the JPG version back into the Blob?
Update: The error message is
[Error] (1: 0): IMAGE_CONVERTER:28: cannot find symbol
[Error] (1: 0): symbol : method write(java.awt.image.BufferedImage,java.lang.String,java.lang.Object)
[Error] (1: 0): location: class javax.imageio.ImageIO
[Error] (1: 0): ImageIO.write(image, "jpg", outputStream);
[Error] (1: 0): ^
[Error] (1: 0): 1 error