use of loci.formats.gui.BufferedImageWriter in project digilib by robcast.
the class BioFormatsDocuImage method writeImage.
@Override
public void writeImage(String mt, OutputStream ostream) throws ImageOpException, FileOpException {
logger.debug("writeImage");
File outFile;
String filext = ".jpg";
if (mt.equals("image/png")) {
filext = ".png";
}
try {
outFile = File.createTempFile("biof_temp", filext);
} catch (IOException e) {
throw new FileOpException(e.toString());
}
// save image to file
ImageWriter iw = new ImageWriter();
/*
* try { //iw.setMetadataRetrieve(new DummyMetadata());
* //iw.setSeries(0); //iw.setId(outFile.getAbsolutePath());
* //logger.debug("writer="+iw); } catch (FormatException e) { throw new
* FileOpException(e.toString()); } catch (IOException e) { // TODO
* Auto-generated catch block e.printStackTrace(); } /* if
* (mt.endsWith("png")) { iw = }
*/
BufferedImageWriter writer = BufferedImageWriter.makeBufferedImageWriter(iw);
try {
logger.debug("setting metadata " + meta);
iw.setMetadataRetrieve(meta);
logger.debug("writing to file " + outFile);
writer.setId(outFile.getAbsolutePath());
logger.debug("fixing metadata " + meta);
iw.setInterleaved(reader.isInterleaved());
iw.setWriteSequentially(true);
meta.setPixelsSizeX(new PositiveInteger(img.getWidth()), 0);
meta.setPixelsSizeY(new PositiveInteger(img.getHeight()), 0);
meta.setPixelsSizeC(new PositiveInteger(img.getColorModel().getNumComponents()), 0);
logger.debug("saving image " + img);
writer.saveImage(0, img);
logger.debug("closing file");
writer.close();
} catch (FormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// now send file
FileInputStream inFile = null;
try {
inFile = new FileInputStream(outFile);
byte[] dataBuffer = new byte[4096];
int len;
while ((len = inFile.read(dataBuffer)) != -1) {
// copy out file
ostream.write(dataBuffer, 0, len);
}
} catch (IOException e) {
throw new FileOpException(e.toString());
} finally {
try {
if (inFile != null) {
inFile.close();
}
} catch (IOException e) {
// nothing to do
}
}
}
use of loci.formats.gui.BufferedImageWriter in project bioformats by openmicroscopy.
the class SumPlanes method main.
public static void main(String[] args) throws Exception {
String id = args[0];
BufferedImageReader r = new BufferedImageReader();
System.out.print("Reading " + id);
r.setId(id);
int imageCount = r.getImageCount();
BufferedImage[] images = new BufferedImage[imageCount];
for (int i = 0; i < imageCount; i++) {
System.out.print(".");
images[i] = r.openImage(i);
}
r.close();
System.out.println(" [done]");
String outId = id + ".tif";
BufferedImageWriter w = new BufferedImageWriter();
System.out.print("Writing " + outId);
w.setId(outId);
w.saveImage(0, sum(images));
w.close();
System.out.println(" [done]");
}
Aggregations