C
carl.manaster
Hi,
I'm using the following code, copied off the internet, to translate a
TIF file to JPEG format. It works, but runs out of memory on one of my
machines. I can "solve" that by giving Java more memory at launch, but
this is running in a context where I don't have easy access to those
parameters, so I would prefer to reduce the memory requirements for the
function. I'm still reading up on JAI and it's a lot to take in at one
time; I'd appreciate any pointers to more memory-efficient ways to go
about this. Thanks!
Peace,
--Carl
public static void main(String[] args) {
final String path = "//images//sample";
RenderedImage image = JAI.create("fileload", path + ".tif");
WritableRaster raster = image.copyData(null);
writeJpegFile(path + ".jpg", image, raster);
}
private static void writeJpegFile(
String filename,
RenderedImage image,
WritableRaster raster) {
BufferedImage bi = new BufferedImage(
image.getColorModel(),
raster,
true,
null);
BufferedImage bi2 = new BufferedImage(
bi.getWidth(),
bi.getHeight(),
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2 = bi2.createGraphics();
g2.drawImage(bi, 0, 0, null);
PlanarImage pi = PlanarImage.wrapRenderedImage(bi2);
JAI.create(
"FileStore",
pi,
filename,
"JPEG",
new JPEGEncodeParam());
}
I'm using the following code, copied off the internet, to translate a
TIF file to JPEG format. It works, but runs out of memory on one of my
machines. I can "solve" that by giving Java more memory at launch, but
this is running in a context where I don't have easy access to those
parameters, so I would prefer to reduce the memory requirements for the
function. I'm still reading up on JAI and it's a lot to take in at one
time; I'd appreciate any pointers to more memory-efficient ways to go
about this. Thanks!
Peace,
--Carl
public static void main(String[] args) {
final String path = "//images//sample";
RenderedImage image = JAI.create("fileload", path + ".tif");
WritableRaster raster = image.copyData(null);
writeJpegFile(path + ".jpg", image, raster);
}
private static void writeJpegFile(
String filename,
RenderedImage image,
WritableRaster raster) {
BufferedImage bi = new BufferedImage(
image.getColorModel(),
raster,
true,
null);
BufferedImage bi2 = new BufferedImage(
bi.getWidth(),
bi.getHeight(),
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2 = bi2.createGraphics();
g2.drawImage(bi, 0, 0, null);
PlanarImage pi = PlanarImage.wrapRenderedImage(bi2);
JAI.create(
"FileStore",
pi,
filename,
"JPEG",
new JPEGEncodeParam());
}