Java 类javax.imageio.stream.FileImageOutputStream 实例源码

项目:litiengine    文件:ImageSerializer.java   
public static void saveImage(final String fileName, final BufferedImage image, ImageFormat imageFormat) {
  try {
    final File file = new File(fileName);
    final String extension = FileUtilities.getExtension(fileName);
    Iterator<ImageWriter> iter = null;
    if (canWriteFormat(extension)) {
      iter = ImageIO.getImageWritersByFormatName(extension);
    } else {
      iter = ImageIO.getImageWritersByFormatName(imageFormat.toString());
    }

    final ImageWriter writer = iter.next();
    final ImageWriteParam iwp = writer.getDefaultWriteParam();

    file.getParentFile().mkdirs();
    try (final FileImageOutputStream output = new FileImageOutputStream(file.getAbsoluteFile())) {
      writer.setOutput(output);
      final IIOImage outimage = new IIOImage(image, null, null);
      writer.write(null, outimage, iwp);
      writer.dispose();
    }
  } catch (final IOException e) {
    log.log(Level.SEVERE, e.getMessage(), e);
  }
}
项目:chordatlas    文件:Imagez.java   
public static void writeJPG( BufferedImage rendered, float quality, File f ) {

        try {
            JPEGImageWriteParam jpegParams = new JPEGImageWriteParam( null );
            jpegParams.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
            jpegParams.setCompressionQuality( 1f );

            ImageWriter writer = ImageIO.getImageWritersByFormatName( "jpeg" ).next();
            ImageWriteParam param = writer.getDefaultWriteParam();
            param.setCompressionMode( ImageWriteParam.MODE_EXPLICIT ); // Needed see javadoc
            param.setCompressionQuality( quality ); // Highest quality
            writer.setOutput( new FileImageOutputStream( f ) );
            writer.write( null, new IIOImage( rendered, null, null ), jpegParams );
        } catch ( Throwable th ) {
            th.printStackTrace();
        }
    }
项目:GazePlay    文件:HeatChart.java   
private void saveGraphicJpeg(BufferedImage chart, File outputFile, float quality) throws IOException {
    // Setup correct compression for jpeg.
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = (ImageWriter) iter.next();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwp.setCompressionQuality(quality);

    // Output the images.
    FileImageOutputStream output = new FileImageOutputStream(outputFile);
    writer.setOutput(output);
    IIOImage image = new IIOImage(chart, null, null);
    writer.write(null, image, iwp);
    writer.dispose();

}
项目:openjdk-jdk10    文件:ImageStreamFromRAF.java   
public static void main(String[] args) {
    try {
        File f = new File("ImageInputStreamFromRAF.tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        ImageInputStream istream = ImageIO.createImageInputStream(raf);
        ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
        f.delete();
        if (istream == null) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
        }
        if (ostream == null) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
        }
        if (!(istream instanceof FileImageInputStream)) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
        }
        if (!(ostream instanceof FileImageOutputStream)) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Unexpected IOException: " + ioe);
    }
}
项目:4Space-5    文件:MapUtil.java   
@SideOnly(Side.CLIENT)
public static void writeImgToFile(BufferedImage img, String name)
{
    if (GalacticraftCore.enableJPEG)
    {
        File folder = new File(FMLClientHandler.instance().getClient().mcDataDir, "assets/temp");

        try {
        ImageOutputStream outputStreamA = new FileImageOutputStream(new File(folder, name));  
        GalacticraftCore.jpgWriter.setOutput(outputStreamA);
        GalacticraftCore.jpgWriter.write(null, new IIOImage(img, null, null), GalacticraftCore.writeParam);
        outputStreamA.close();
        }
        catch (Exception e) { }
    }
}
项目:mid    文件:Requester.java   
public static void downloadImage(String imgURL, InputStream postInStr) 
        throws IOException {
    BufferedImage image = ImageIO.read(postInStr);

    String[] URLparts = imgURL.split("/");
    File outputFile = new File(saveFolderName + "/" + URLparts[URLparts.length - 1]);

    JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(null);
    jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    jpegParams.setCompressionQuality(1f);

    final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next();
    writer.setOutput(new FileImageOutputStream(outputFile));
    writer.write(null, new IIOImage(image, null, null), jpegParams);

    System.out.println("Got " + outputFile + " from " + imgURL);
}
项目:RayPlus    文件:Main.java   
public static void main(String[] args) {
    JFrame frame = new JFrame();
    BufferedImage image = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    frame.getContentPane().add(new JLabel(new ImageIcon(image)));
    frame.setSize(image.getHeight() + frame.getSize().height, image.getWidth() + frame.getSize().width);
    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setVisible(true);
    try {
        ImageOutputStream output = new FileImageOutputStream(new File("anim.gif"));
        GifSequenceWriter writer = new GifSequenceWriter(output, image.getType(), (int)(1000/FPS), true);
        for (int i = 0; i < FPS*GIF_LENGTH; i++) {
            Scene scene = constructScene(i/(FPS*GIF_LENGTH));
            scene.render(image, frame);
            writer.writeToSequence(image);
        }
        writer.close();
        output.close();
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
    File outFile = new File("image.png");
}
项目:PhET    文件:ScreenshotProcessor.java   
private void writeCompressedJPG( BufferedImage image, File file, float quality ) throws IOException {
        Iterator iter = ImageIO.getImageWritersByFormatName( "jpeg" );
        ImageWriter writer = (ImageWriter) iter.next();
// instantiate an ImageWriteParam object with default compression options
        ImageWriteParam iwp = writer.getDefaultWriteParam();

//Now, we can set the compression quality:
        iwp.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
        iwp.setCompressionQuality( quality );   // an integer between 0 and 1
// 1 specifies minimum compression and maximum quality


//Output the file:

        FileImageOutputStream output = new FileImageOutputStream( file );
        writer.setOutput( output );
        IIOImage a = new IIOImage( image, null, null );
        writer.write( null, a, iwp );
    }
项目:jdk8u_jdk    文件:ImageStreamFromRAF.java   
public static void main(String[] args) {
    try {
        File f = new File("ImageInputStreamFromRAF.tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        ImageInputStream istream = ImageIO.createImageInputStream(raf);
        ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
        f.delete();
        if (istream == null) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
        }
        if (ostream == null) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
        }
        if (!(istream instanceof FileImageInputStream)) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
        }
        if (!(ostream instanceof FileImageOutputStream)) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Unexpected IOException: " + ioe);
    }
}
项目:SweetHome3D    文件:PhotosPanel.java   
/**
 * Saves the given <code>image</code>.
 */
private void savePhoto(BufferedImage image, File file) throws IOException
{
    String fileFormat = this.controller.getFileFormat();
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(fileFormat);
    ImageWriter writer = (ImageWriter) iter.next();
    ImageWriteParam writeParam = writer.getDefaultWriteParam();
    if ("JPEG".equals(fileFormat))
    {
        writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        writeParam.setCompressionQuality(this.controller.getFileCompressionQuality());
    }
    FileImageOutputStream output = new FileImageOutputStream(file);
    writer.setOutput(output);
    writer.write(null, new IIOImage(image, null, null), writeParam);
    writer.dispose();
    output.close();
}
项目:repo.kmeanspp.silhouette_score    文件:HeatChart.java   
private void saveGraphicJpeg(BufferedImage chart, File outputFile,
  float quality) throws IOException {
  // Setup correct compression for jpeg.
  Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
  ImageWriter writer = iter.next();
  ImageWriteParam iwp = writer.getDefaultWriteParam();
  iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  iwp.setCompressionQuality(quality);

  // Output the image.
  FileImageOutputStream output = new FileImageOutputStream(outputFile);
  writer.setOutput(output);
  IIOImage image = new IIOImage(chart, null, null);
  writer.write(null, image, iwp);
  writer.dispose();

}
项目:SAX    文件:HeatChart.java   
private void saveGraphicJpeg(BufferedImage chart, File outputFile, float quality)
    throws IOException {
  // Setup correct compression for jpeg.
  Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
  ImageWriter writer = (ImageWriter) iter.next();
  ImageWriteParam iwp = writer.getDefaultWriteParam();
  iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  iwp.setCompressionQuality(quality);

  // Output the image.
  FileImageOutputStream output = new FileImageOutputStream(outputFile);
  writer.setOutput(output);
  IIOImage image = new IIOImage(chart, null, null);
  writer.write(null, image, iwp);
  writer.dispose();

}
项目:polapi    文件:MonochromImage.java   
@Override
public void run() {
    // make image
    wr.setPixels(0, 0, WIDTH, HEIGHT, pixList);
    bufImage.setData(wr);
    outputImage = new IIOImage(bufImage, null, null);

    // make filename with date
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
    String dateString = sdf.format(new Date());

    // file to write
    File imageFile = new File(filePath+dateString+".jpg");

    //write jpeg image file
    try {
        jpgWriter.setOutput(new FileImageOutputStream( imageFile ));
        jpgWriter.write(null, outputImage, jpgWriteParam);
    } catch (IOException e) {
        e.printStackTrace();
    } 
}
项目:sc2gears    文件:ImageConverter.java   
private static void convertImages( final File file ) throws Exception {
    if ( file.isDirectory() ) {
        for ( final File childFile : file.listFiles() )
            convertImages( childFile );
    }
    else {
        final BufferedImage bi = ImageIO.read( file );

        // Default quality is not sufficient!
        // ImageIO.write( bi, "JPG", new File( file.getPath().replace( ".png", ".jpg" ) ) );

        final ImageWriter     iw  = ImageIO.getImageWritersByFormatName( "jpg" ).next();
        final ImageWriteParam iwp = iw.getDefaultWriteParam();

        iwp.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
        iwp.setCompressionQuality( 0.9f );

        iw.setOutput( new FileImageOutputStream( new File( file.getPath().replace( ".png", ".jpg" ) ) ) );
        iw.write( null, new IIOImage( bi , null, null ), iwp );
        iw.dispose();
    }
}
项目:selfpi    文件:MonochromImageWin.java   
@Override
        public void run() {
            // make image
            wr.setPixels(0, 0, WIDTH, HEIGHT, getFloydDitheredMonochrom());   //dithered image
//          wr.setPixels(0, 0, WIDTH, HEIGHT, pixList);  // grayscale image     
//          wr.setPixels(0, 0, WIDTH, HEIGHT, getJarvisDitheredMonochom());   //dithered image
//          wr.setPixels(0, 0, WIDTH, HEIGHT, pixContrasted);    // grayscale image     

            bufImage.setData(wr);
            outputImage = new IIOImage(bufImage, null, null);

            // make filename with date
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
            String dateString = sdf.format(new Date());

            // file to write
            File imageFile = new File(filePath+dateString+".jpg");

            //write jpeg image file
            try {
                imageWriter.setOutput(new FileImageOutputStream( imageFile ));
                imageWriter.write(null, outputImage, imageWriteParam);
            } catch (IOException e) {
                e.printStackTrace();
            } 
        }
项目:olat    文件:ImageHelper.java   
/**
 * Can change this to choose a better compression level as the default
 * 
 * @param image
 * @param scaledImage
 * @return
 */
private static boolean writeTo(BufferedImage image, File scaledImage, Size scaledSize, String outputFormat) {
    try {
        if (!StringHelper.containsNonWhitespace(outputFormat)) {
            outputFormat = OUTPUT_FORMAT;
        }

        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(outputFormat);
        if (writers.hasNext()) {
            ImageWriter writer = writers.next();
            ImageWriteParam iwp = getOptimizedImageWriteParam(writer, scaledSize);
            IIOImage iiOImage = new IIOImage(image, null, null);
            ImageOutputStream iOut = new FileImageOutputStream(scaledImage);
            writer.setOutput(iOut);
            writer.write(null, iiOImage, iwp);
            writer.dispose();
            iOut.flush();
            iOut.close();
            return true;
        } else {
            return ImageIO.write(image, outputFormat, scaledImage);
        }
    } catch (IOException e) {
        return false;
    }
}
项目:olat    文件:ImageHelper.java   
/**
 * Can change this to choose a better compression level as the default
 * 
 * @param image
 * @param scaledImage
 * @return
 */
private static boolean writeTo(BufferedImage image, File scaledImage, Size scaledSize, String outputFormat) {
    try {
        if (!StringHelper.containsNonWhitespace(outputFormat)) {
            outputFormat = OUTPUT_FORMAT;
        }

        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(outputFormat);
        if (writers.hasNext()) {
            ImageWriter writer = writers.next();
            ImageWriteParam iwp = getOptimizedImageWriteParam(writer, scaledSize);
            IIOImage iiOImage = new IIOImage(image, null, null);
            ImageOutputStream iOut = new FileImageOutputStream(scaledImage);
            writer.setOutput(iOut);
            writer.write(null, iiOImage, iwp);
            writer.dispose();
            iOut.flush();
            iOut.close();
            return true;
        } else {
            return ImageIO.write(image, outputFormat, scaledImage);
        }
    } catch (IOException e) {
        return false;
    }
}
项目:selenium-utils    文件:ILBMEncoder.java   
public void write(File f, BitmapImage img, int camg) throws IOException {
    IFFOutputStream out = null;
    try {
        out = new IFFOutputStream(new FileImageOutputStream(f));

        out.pushCompositeChunk("FORM", "ILBM");
        writeBMHD(out, img);
        writeCMAP(out, img);
        writeCAMG(out, camg);
        writeBODY(out, img);
        out.popChunk();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}
项目:BattleNationsAnimation    文件:GifAnimation.java   
public void write(File file) throws IOException {
    ImageWriter writer = getWriter();
    IIOImage[] images = getImageSequence(writer);
    file.delete();
    ImageOutputStream out = new FileImageOutputStream(file);
    try {
        writer.setOutput(out);
        writer.prepareWriteSequence(null);
        for (IIOImage img : images)
            writer.writeToSequence(img, null);
        writer.endWriteSequence();
    }
    finally {
        out.close();
    }
}
项目:Juicebox    文件:HeatChart.java   
private void saveGraphicJpeg(BufferedImage chart, File outputFile, float quality) throws IOException {
    // Setup correct compression for jpeg.
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = iter.next();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwp.setCompressionQuality(quality);

    // Output the image.
    FileImageOutputStream output = new FileImageOutputStream(outputFile);
    writer.setOutput(output);
    IIOImage image = new IIOImage(chart, null, null);
    writer.write(null, image, iwp);
    writer.dispose();

}
项目:Gif-Screen-Capture    文件:ScreenCapture.java   
public void createWriter(File file, int time, boolean loop,
        Rectangle bounds, boolean lc) throws IOException, AWTException {
    lowcolor = lc;
    writer = new GifSequenceWriter(new FileImageOutputStream(file),
            BufferedImage.TYPE_INT_ARGB, time, loop);
    writer.imageWriteParam
            .setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    writer.imageWriteParam.setCompressionType("LZW");
    this.bounds = bounds;
    this.x = bounds.x;
    this.y = bounds.y;
    this.w = bounds.width;
    this.h = bounds.height;
    this.time = time;
    rt = new Robot();

    WriterThread.setup(writer, lowcolor);
}
项目:jpexs-decompiler    文件:FrameExporter.java   
public static void makeGIFOld(Iterator<BufferedImage> images, float frameRate, File file, EventListener evl) throws IOException {
    if (!images.hasNext()) {
        return;
    }

    try (ImageOutputStream output = new FileImageOutputStream(file)) {
        BufferedImage img0 = images.next();
        GifSequenceWriter writer = new GifSequenceWriter(output, img0.getType(), (int) (1000.0 / frameRate), true);
        writer.writeToSequence(img0);

        while (images.hasNext()) {
            writer.writeToSequence(images.next());
        }

        writer.close();
    }
}
项目:image-processing    文件:TIFFEncoder.java   
/**
 * writeLeftAlignedValue() writes a given value of the given type into
 * a given stream as a left-justified four-byte record.
 * See Section 2 (page 15) of the TIFF spec for details.
 *
 * @param stream the stream representing the file being written.
 * @param type the type of the value.
 * @param val the value to write.
 * @throws IOException
 */
private static void writeLeftAlignedValue(FileImageOutputStream stream,
                                          TiffType type, int val)
                                         throws IOException {
  switch (type) {
  case SHORT:
    stream.writeShort(val);
    stream.writeShort(0);
    break;
  case LONG:
    stream.writeInt(val);
    break;
  default:  // There are other possible types, but we're not using them.
    throw new IllegalArgumentException();
  }
}
项目:im4java    文件:ImageCommand.java   
/**
 * Write a BufferedImage to a temporary file.
 */

private String convert2TmpFile(BufferedImage pBufferedImage)
                                                           throws IOException {
  String tmpFile = getTmpFile();
  ImageTypeSpecifier spec = 
    ImageTypeSpecifier.createFromRenderedImage(pBufferedImage);
  Iterator<ImageWriter> iter;
  iter = ImageIO.getImageWriters(spec,"TIFF");
  if (!iter.hasNext()) {
    iter = ImageIO.getImageWriters(spec,"PNG");
  }
  if (iter.hasNext()) {
    ImageWriter writer = (ImageWriter) iter.next();
    FileImageOutputStream fios = new FileImageOutputStream(new File(tmpFile));
    writer.setOutput(fios);
    writer.write(pBufferedImage);
    fios.close();
    writer.dispose();
  }
  return tmpFile;
}
项目:cs61b    文件:TIFFEncoder.java   
/**
 * writeLeftAlignedValue() writes a given value of the given type into
 * a given stream as a left-justified four-byte record.
 * See Section 2 (page 15) of the TIFF spec for details.
 *
 * @param stream the stream representing the file being written.
 * @param type the type of the value.
 * @param val the value to write.
 * @throws IOException
 */
private static void writeLeftAlignedValue(FileImageOutputStream stream,
                                          TiffType type, int val)
                                         throws IOException {
  switch (type) {
  case SHORT:
    stream.writeShort(val);
    stream.writeShort(0);
    break;
  case LONG:
    stream.writeInt(val);
    break;
  default:  // There are other possible types, but we're not using them.
    throw new IllegalArgumentException();
  }
}
项目:Feuille    文件:WavePanel.java   
private boolean writeInImageOutput(FileImageOutputStream fileIOS,
        BufferedImage bi, boolean andCloseIt){
    try{
        //Appends new graphics to the output
        ImageIO.write(bi, "PNG", fileIOS);
        if(andCloseIt==false){
            fileIOS.flush();
        }else{
            fileIOS.close();
        }

    }catch (java.io.IOException ioe){
        System.out.println("PNG Aborted");
        return false;
    }
    return true;
}
项目:montemedia    文件:ILBMEncoder.java   
public void write(File f, BitmapImage img, int camg) throws IOException {
    IFFOutputStream out = null;
    try {
        out = new IFFOutputStream(new FileImageOutputStream(f));

        out.pushCompositeChunk("FORM", "ILBM");
        writeBMHD(out, img);
        writeCMAP(out, img);
        writeCAMG(out, camg);
        writeBODY(out, img);
        out.popChunk();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}
项目:sejda    文件:PageImageWriter.java   
public static String convertImageTo(String filePath, String format) throws IOException, TaskIOException {
    BufferedImage image = ImageIO.read(new File(filePath));
    File tmpFile = IOUtils.createTemporaryBuffer("." + format);
    ImageOutputStream outputStream = new FileImageOutputStream(tmpFile);

    try {
        ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
        writer.setOutput(outputStream);
        ImageWriteParam param = writer.getDefaultWriteParam();
        if (format.equals("jpeg")) {
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            param.setCompressionQuality(1.0F);
        }
        writer.write(null, new IIOImage(image, null, null), param);
    } finally {
        org.apache.commons.io.IOUtils.closeQuietly(outputStream);
    }

    return tmpFile.getPath();
}
项目:Server-Application    文件:ImageResizeService.java   
private void writeJPEG(BufferedImage input, ImageResizeRequest imageResizeRequest) throws IOException {
  Iterator iter = ImageIO.getImageWritersByFormatName("JPG");
  if (iter.hasNext()) {
    ImageWriter writer = (ImageWriter) iter.next();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwp.setCompressionQuality(imageResizeRequest.getCompressionQuality());

    File outFile = new File(imageResizeRequest.getDestinationFilePath());
    FileImageOutputStream output = new FileImageOutputStream(outFile);
    writer.setOutput(output);
    IIOImage image = new IIOImage(input, null, null);
    writer.write(null, image, iwp);

    output.close();
  }
}
项目:termitaria    文件:ImageUtils.java   
public void writeImageToFile(BufferedImage input, String fileName) throws IOException {
    logger.debug("writeImageToFile " + fileName);
    Iterator iter = ImageIO.getImageWritersByFormatName("JPG");
    if (iter.hasNext()) {
        ImageWriter writer = (ImageWriter) iter.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(0.95f);
        File outFile = new File(fileName);
        FileImageOutputStream output = new FileImageOutputStream(outFile);
        writer.setOutput(output);
        IIOImage image =
            new IIOImage(input, null, null);
        writer.write(null, image, iwp);
        output.close();
    }
}
项目:lapdftext    文件:JPedalPDFRenderer.java   
private void writeImage(File outputFile, BufferedImage img)
        throws FileNotFoundException, IOException {

    Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter iw = it.next();
    ImageWriteParam iwp = iw.getDefaultWriteParam();
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwp.setCompressionQuality(1);

    FileImageOutputStream outs = new FileImageOutputStream(outputFile);
    iw.setOutput(outs);
    IIOImage ioimage = new IIOImage(img, null, null);
    iw.write(null, ioimage, iwp);
    iw.dispose();

}
项目:OpenJSharp    文件:FileImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
项目:OpenJSharp    文件:RAFImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof RandomAccessFile) {
        try {
            return new FileImageOutputStream((RandomAccessFile)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
项目:jdk8u-jdk    文件:FileImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
项目:jdk8u-jdk    文件:RAFImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof RandomAccessFile) {
        try {
            return new FileImageOutputStream((RandomAccessFile)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
项目:openjdk-jdk10    文件:FileImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
项目:openjdk-jdk10    文件:RAFImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof RandomAccessFile) {
        try {
            return new FileImageOutputStream((RandomAccessFile)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
项目:openjdk9    文件:FileImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
项目:openjdk9    文件:RAFImageOutputStreamSpi.java   
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof RandomAccessFile) {
        try {
            return new FileImageOutputStream((RandomAccessFile)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
项目:memoria-politica    文件:FedDepPhotosUtility.java   
private static boolean compressImageFile(ImageWriter jpgWriter, ImageWriteParam jpgWriteParam, File inputFile, File outputFile) throws IOException {
    BufferedImage image = null;
    try {
        /* Para evitar problemas na leitura de imagens JPEG com
           modelo de cor CMYK um leitor terceiro é utilizado como extensão do ImageIO,
           Por isso precisamos da dependência: com.twelvemonkeys.imageio:imageio-jpeg.
           A extensão é instalada automaticamente, basta estar no classpath.
         */
        image = ImageIO.read(inputFile);
    }
    catch (Exception ex) {
        System.out.println("Falha ao ler arquivo com ImageIO.");
        ex.printStackTrace();
    }

    IIOImage outputImage = new IIOImage(image, null, null);

    if (!outputFile.exists()) {
        if (!outputFile.getParentFile().exists() && !outputFile.getParentFile().mkdirs()) {
            System.out.println("Não foi possível criar os diretórios intermediários para salvar o arquivo no caminho: " + outputFile.getAbsolutePath());
            return false;
        }

        if (!outputFile.createNewFile()) {
            System.out.println("Não foi possível criar o arquivo: " + outputFile.getAbsolutePath());
            return false;
        }
    }
    ImageOutputStream outputStream = new FileImageOutputStream(outputFile);
    jpgWriter.setOutput(outputStream);
    jpgWriter.write(null, outputImage, jpgWriteParam);

    return true;
}