use of ij.plugin.PNG_Writer in project digilib by robcast.
the class ImageJ1DocuImage method writeImage.
/* (non-Javadoc)
* @see digilib.image.DocuImageImpl#writeImage(java.lang.String, java.io.OutputStream)
*/
@Override
public void writeImage(String mt, OutputStream ostream) throws ImageOpException, FileOpException {
File outFile;
String filext = ".jpg";
if (mt.equals("image/png")) {
filext = ".png";
}
try {
outFile = File.createTempFile("imgj_temp", filext);
} catch (IOException e) {
throw new FileOpException(e.toString());
}
// save image to file
logger.debug("writeImage: mt=" + mt);
if (mt.equals("image/png")) {
PNG_Writer writer = new PNG_Writer();
try {
img = new ImagePlus("Image", proc);
writer.writeImage(img, outFile.getAbsolutePath(), 0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
img = new ImagePlus("Image", proc);
JpegWriter.save(img, outFile.getAbsolutePath(), 70);
}
// 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
}
}
}
Aggregations