Search in sources :

Example 1 with PNG_Writer

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
        }
    }
}
Also used : PNG_Writer(ij.plugin.PNG_Writer) FileOpException(digilib.io.FileOpException) IOException(java.io.IOException) File(java.io.File) ImagePlus(ij.ImagePlus) IOException(java.io.IOException) FileOpException(digilib.io.FileOpException) FileInputStream(java.io.FileInputStream)

Aggregations

FileOpException (digilib.io.FileOpException)1 ImagePlus (ij.ImagePlus)1 PNG_Writer (ij.plugin.PNG_Writer)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1