JasperReports - 在数据库中显示存储在 BLOB 中的 tiff
JasperReports - displaying tiff's stored in BLOB in db
我想显示一些存储在 Oracle 数据库中的 BLOB 中的 tiff。我只是尝试使用 im4java 将它们从 tiff 转换为 jpg 或 png,但这没有用。也许有可能在不转换的情况下在 Jasper 中显示 .tiff 和其他 img 数据类型?!或者,如果没有,是否有人有详细的解决方案如何转换它们? (我需要配置哪个图像class,如何在scriptlet中实现等等)
谢谢大家!
IMOperation op = new IMOperation();
op.addImage();
op.addImage();
ConvertCmd convert = new ConvertCmd();
convert.run(op, new Object[]{inputImage.getAbsolutePath(), outputImage.getAbsolutePath()});
return outputImage;`
问题已解决,这是我使用 jai-imageIO.jar 将 tiff 转换为 jpg 的代码:
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.imageio.spi.IIORegistry;
import net.sf.jasperreports.engine.JRAbstractScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;
public static InputStream convertTifToPng(InputStream inputImage)
throws IOException, InterruptedException {
IIORegistry registry = IIORegistry.getDefaultInstance();
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriterSpi());
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderSpi());
BufferedImage image;
if (inputImage != null) {
image = ImageIO.read(inputImage);
} else {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
InputStream outputImage = new ByteArrayInputStream(baos.toByteArray());
return outputImage;
}
我想显示一些存储在 Oracle 数据库中的 BLOB 中的 tiff。我只是尝试使用 im4java 将它们从 tiff 转换为 jpg 或 png,但这没有用。也许有可能在不转换的情况下在 Jasper 中显示 .tiff 和其他 img 数据类型?!或者,如果没有,是否有人有详细的解决方案如何转换它们? (我需要配置哪个图像class,如何在scriptlet中实现等等)
谢谢大家!
IMOperation op = new IMOperation();
op.addImage();
op.addImage();
ConvertCmd convert = new ConvertCmd();
convert.run(op, new Object[]{inputImage.getAbsolutePath(), outputImage.getAbsolutePath()});
return outputImage;`
问题已解决,这是我使用 jai-imageIO.jar 将 tiff 转换为 jpg 的代码:
import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream;
import javax.imageio.ImageIO; import javax.imageio.spi.IIORegistry;
import net.sf.jasperreports.engine.JRAbstractScriptlet; import net.sf.jasperreports.engine.JRScriptletException;
public static InputStream convertTifToPng(InputStream inputImage)
throws IOException, InterruptedException {
IIORegistry registry = IIORegistry.getDefaultInstance();
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriterSpi());
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderSpi());
BufferedImage image;
if (inputImage != null) {
image = ImageIO.read(inputImage);
} else {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
InputStream outputImage = new ByteArrayInputStream(baos.toByteArray());
return outputImage;
}