Transcode file to PNG.

@param file Output filename
@param width Width
@param height Height
@throws IOException On write errors
@throws TranscoderException On input/parsing errors.
486442
public void saveAsPNG(File file, int width, int height) throws IOException, TranscoderException {
    PNGTranscoder t = new PNGTranscoder();
    t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width));
    t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(height));
    transcode(file, t);
  }
1128659
public void saveAsPDF(File file) throws IOException, TranscoderException, ClassNotFoundException {
    try {
      Object t = Class.forName("org.apache.fop.svg.PDFTranscoder").newInstance();
      transcode(file, (Transcoder) t);
    }
    catch(InstantiationException | IllegalAccessException e) {
      throw new ClassNotFoundException("Could not instantiate PDF transcoder - is Apache FOP installed?", e);
    }
  }
791188
public static void outputImage(int w, int h, File outputFile, String code) throws IOException{
        if(outputFile == null){
            return;
        }
        File dir = outputFile.getParentFile();
        if(!dir.exists()){
            dir.mkdirs();
        }
        try{
            outputFile.createNewFile();
            FileOutputStream fos = new FileOutputStream(outputFile);
            outputImage(w, h, fos, code);
            fos.close();
        } catch(IOException e){
            throw e;
        }
    }
540774
public static OutputStream toFile(File file) throws FileNotFoundException {
		if(file != null) {
			return new FileOutputStream(file);
		}
		return null;
	}
314856
public static void encode2ImgFile(int width, int high, String imgFilename, String verifyCode) throws IOException{
        width = width < 1 ? defaultWidth : width;
        high = high < 1 ? defaultHigh : high;
        File outputFile = new File(imgFilename);
        File dir = outputFile.getParentFile();
        if(!dir.exists()){
            dir.mkdirs();
        }
        outputFile.createNewFile();
        FileOutputStream fos = new FileOutputStream(outputFile);
        outputImage(width, high, fos, verifyCode);
        fos.close();
    }
410466
public static BufferedImage convertFromSvg(final URI svgFile, final int width, final int height)
            throws TranscoderException {
        BufferedImageTranscoder imageTranscoder = new BufferedImageTranscoder();

        imageTranscoder.addTranscodingHint(TIFFTranscoder.KEY_WIDTH, (float) width);
        imageTranscoder.addTranscodingHint(TIFFTranscoder.KEY_HEIGHT, (float) height);

        TranscoderInput input = new TranscoderInput(svgFile.toString());
        imageTranscoder.transcode(input, null);

        return imageTranscoder.getBufferedImage();
    }
549938
public static void setBytes(File file, byte[] bytes) throws IOException {
        IOGroovyMethods.setBytes(new FileOutputStream(file), bytes);
    }
528235
public static File writeToStream(File file, OutputStream out) throws IORuntimeException {
		return FileReader.create(file).writeToStream(out);
	}
470212
public static void write(CharSequence content, File file, String encoding) {
        OutputStream os = null;
        try {
            os = new FileOutputStream(file);
            PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os, encoding));
            printWriter.print(content);
            printWriter.flush();
            os.flush();
        } catch (IOException e) {
            throw E.unexpected(e);
        } finally {
            close(os);
        }
    }
249668
public void save(File file) throws IOException {
        BufferedImage bi = new BufferedImage(canvas.getWidth(), canvas.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = bi.createGraphics();
        canvas.print(g2d);

        ImageIO.write(bi, FileChooser.getExtension(file), file);
    }
208257
public static void writePng(Image image, ImageOutputStream destImageStream) throws IORuntimeException {
		write(image, IMAGE_TYPE_PNG, destImageStream);
	}
1164649
public static void saveImage(BufferedImage image, OutputStream output) throws IOException
    {
        ImageIO.write(image, "png", output);
    }
999582
private static void writeHeader(Path file) throws IOException {
        try (FileChannel fout = FileChannel.open(file, StandardOpenOption.WRITE)) {

            long size = fout.size();
            int sampleSize = (int) size - 44;

            if (logger.isInfoEnabled()) {
                logger.info("Size  " + sampleSize + " of recording file " + file);
            }

            ByteBuffer headerBuffer = ByteBuffer.allocateDirect(44);
            headerBuffer.clear();
            // RIFF
            headerBuffer.put((byte) 0x52);
            headerBuffer.put((byte) 0x49);
            headerBuffer.put((byte) 0x46);
            headerBuffer.put((byte) 0x46);

            int length = sampleSize + 36;

            // Length
            headerBuffer.put((byte) (length));
            headerBuffer.put((byte) (length >> 8));
            headerBuffer.put((byte) (length >> 16));
            headerBuffer.put((byte) (length >> 24));

            // WAVE
            headerBuffer.put((byte) 0x57);
            headerBuffer.put((byte) 0x41);
            headerBuffer.put((byte) 0x56);
            headerBuffer.put((byte) 0x45);

            // fmt
            headerBuffer.put((byte) 0x66);
            headerBuffer.put((byte) 0x6d);
            headerBuffer.put((byte) 0x74);
            headerBuffer.put((byte) 0x20);

            headerBuffer.put((byte) 0x10);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);

            // format - PCM
            headerBuffer.put((byte) 0x01);
            headerBuffer.put((byte) 0x00);

            // format - MONO
            headerBuffer.put((byte) 0x01);
            headerBuffer.put((byte) 0x00);

            // sample rate:8000
            headerBuffer.put((byte) 0x40);
            headerBuffer.put((byte) 0x1F);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);

            // byte rate
            headerBuffer.put((byte) 0x80);
            headerBuffer.put((byte) 0x3E);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);

            // Block align
            headerBuffer.put((byte) 0x02);
            headerBuffer.put((byte) 0x00);

            // Bits per sample: 16
            headerBuffer.put((byte) 0x10);
            headerBuffer.put((byte) 0x00);

            // "data"
            headerBuffer.put((byte) 0x64);
            headerBuffer.put((byte) 0x61);
            headerBuffer.put((byte) 0x74);
            headerBuffer.put((byte) 0x61);

            // len
            headerBuffer.put((byte) (sampleSize));
            headerBuffer.put((byte) (sampleSize >> 8));
            headerBuffer.put((byte) (sampleSize >> 16));
            headerBuffer.put((byte) (sampleSize >> 24));

            headerBuffer.rewind();

            // lets write header
            fout.position(0);
            fout.write(headerBuffer);
        }
    }
239161
public void toFile(final File file) throws GitChangelogRepositoryException, IOException {
    createParentDirs(file);
    write(render().getBytes("UTF-8"), file);
  }
24341
public static int resizeImage(BufferedImage inputImage, String dest, int width, int height, float quality)
			throws IOException {
		BufferedImage outputImage = Scalr.resize(inputImage, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
				Scalr.OP_ANTIALIAS);
		return writeImage(dest, outputImage, 0.9f);
	}
137784
public static void create(String data, OutputStream out, int width,
                              int height) throws IOException {
        logger.debug("生成二维码，要生成的图片的宽为{}，高为{}", width, height);
        QRCode code = createQRCode(data, width, height);
        code.writeTo(out);
        out.close();
        logger.debug("二维码生成成功");
    }
118250
public static void renderFile(File file, String responseFileName, int bufferSize) {
		new FileView(file, responseFileName, bufferSize).render();
	
	}