Java Image to BufferedImage toBufferedImage(Image image)

Here you can find the source of toBufferedImage(Image image)

Description

to Buffered Image

License

Open Source License

Declaration

private static BufferedImage toBufferedImage(Image image) 

Method Source Code

//package com.java2s;
/**/*from w w w.  jav a 2  s  . co  m*/
 * aTunes 1.6.0
 * Copyright (C) 2006-2007 Alex Aranda (fleax) alex.aranda@gmail.com
 *
 * http://www.atunes.org
 * http://sourceforge.net/projects/atunes
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;

import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

public class Main {
    private static BufferedImage toBufferedImage(Image image) {
        BufferedImage bufferedImage;
        try {
            image = new ImageIcon(image).getImage();
            bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D g = bufferedImage.createGraphics();
            g.setColor(Color.white);
            g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
            g.drawImage(image, 0, 0, null);
            g.dispose();
        } catch (IllegalArgumentException e) {
            return null;
        }

        return bufferedImage;
    }
}

Related

  1. toBufferedImage(Image image)
  2. toBufferedImage(Image image)
  3. toBufferedImage(Image image)
  4. toBufferedImage(Image image)
  5. toBufferedImage(Image image)
  6. toBufferedImage(Image image)
  7. toBufferedImage(Image image)
  8. toBufferedImage(Image image)
  9. toBufferedImage(Image image)