All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sksamuel.scrimage.nio.TwelveMonkeysWriter Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
package com.sksamuel.scrimage.nio;

import com.sksamuel.scrimage.AwtImage;
import com.sksamuel.scrimage.metadata.ImageMetadata;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.stream.ImageOutputStream;
import java.io.IOException;
import java.io.OutputStream;

abstract class TwelveMonkeysWriter implements ImageWriter {

    public abstract String format();

    @Override
    public void write(AwtImage image, ImageMetadata metadata, OutputStream out) throws IOException {
        javax.imageio.ImageWriter writer = ImageIO.getImageWritersByFormatName(format()).next();
        ImageOutputStream ios = ImageIO.createImageOutputStream(out);
        ImageWriteParam params = writer.getDefaultWriteParam();
        writer.setOutput(ios);
        writer.write(null, new IIOImage(image.awt(), null, null), params);
        ios.close();
        writer.dispose();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy