static public final boolean saveAsTIFF(BufferedImage bi, final String path, final boolean as_grey) { if (!checkPath(path)) return false; synchronized (getPathLock(path)) { OutputStream out = null; try { if (as_grey) bi = asGrey(bi); final TIFFEncodeParam param = new TIFFEncodeParam(); // If the bi is larger than 512x512, I could use COMPRESSION_LZW or COMPRESSION_DEFLATE (zip-in-tiff, lossless), or COMPRESSION_JPEG_TTN2 (Jpeg-in-tiff) -- i.e. an adaptive strategy as suggested by Clay Reid param.setCompression(TIFFEncodeParam.COMPRESSION_NONE); out = new BufferedOutputStream(new FileOutputStream(path)); ImageCodec.createImageEncoder("TIFF", out, param).encode(bi); out.flush(); // !@#$% Couldn't it do it by itself? final File f = new File(path); return f.exists() && f.length() > 0; // no other way to check if the writing was successful } catch (FileNotFoundException fnfe) { Utils.log2("saveAsTIFF: Path not found: " + path); } catch (Exception e) { IJError.print(e, true); } finally { if (null != out) try { out.close(); } catch (Exception e) {} removePathLock(path); } } return false; }
@Override public void convert(InputStream input, OutputStream output) throws IOException { TIFFDecodeParam decodeParam = new TIFFDecodeParam(); decodeParam.setDecodePaletteAsShorts(true); decodeParam.setJPEGDecompressYCbCrToRGB(true); ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", input, decodeParam); try { RenderedImage image = decoder.decodeAsRenderedImage(); ImageEncodeParam encodeParam = new PNGEncodeParam.Palette(); ImageEncoder encoder = ImageCodec.createImageEncoder("png", output, encodeParam); encoder.encode(image); input.close(); } finally { IOUtils.closeQuietly(input); } }
ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg", out, p);
private void exportImages(KmlFeature kmlFeature, ZipOutputStream zipOutputStream, ProgressMonitor pm) throws IOException { if (pm.isCanceled()) { return; } if (kmlFeature instanceof KmlOverlay) { KmlOverlay overlay = (KmlOverlay) kmlFeature; zipOutputStream.putNextEntry(new ZipEntry(overlay.getIconFileName())); ImageEncoder encoder = ImageCodec.createImageEncoder(IMAGE_TYPE, zipOutputStream, null); encoder.encode(overlay.getOverlay()); pm.worked(1); } if (kmlFeature instanceof KmlContainer) { KmlContainer container = (KmlContainer) kmlFeature; for (KmlFeature feature : container.getChildren()) { exportImages(feature, zipOutputStream, pm); } } }
ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg", out, p);
ImageEncoder encoder = ImageCodec.createImageEncoder(IMAGE_TYPE, outStream, null); encoder.encode(image); pm.worked(1); encoder = ImageCodec.createImageEncoder(IMAGE_TYPE, outStream, null); encoder.encode(createImageLegend(view.getRaster())); pm.worked(1);
p.setPaletteTransparency( b ); com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec.createImageEncoder( "PNG", os, encodeParam ); encoder.encode( img.getData(), img.getColorModel() ); } catch ( Exception e ) {
ImageEncoder encoder = ImageCodec.createImageEncoder(IMAGE_TYPE, outStream, null); encoder.encode(image); pm.worked(1); encoder = ImageCodec.createImageEncoder(IMAGE_TYPE, outStream, null); encoder.encode(createImageLegend(view.getRaster())); pm.worked(1);
ImageEncoder enc = ImageCodec.createImageEncoder("tiff", stream, param); enc.encode(image);
ImageEncoder encoder = ImageCodec.createImageEncoder(imageFormat, stream, null); encoder.encode(image); } finally {
ImageEncoder encoder = ImageCodec.createImageEncoder(imageFormat, stream, null); encoder.encode(image);