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

public static BufferedImage toBufferedImage(Image image) 

Method Source Code

//package com.java2s;
/*/*  www. j  a v a2 s  . c o m*/
 * Copyright (C) 2007, 2008 Quadduc <quadduc@gmail.com>
 * Copyright (C) 2007, 2011 IsmAvatar <IsmAvatar@gmail.com>
 * Copyright (C) 2007 Clam <clamisgood@gmail.com>
 * Copyright (C) 2013, Robert B. Colton
 * 
 * This file is part of FLUIDIDE.
 * FLUIDIDE is free software and comes with ABSOLUTELY NO WARRANTY.
 * See LICENSE for details.
 */

import java.awt.Graphics;

import java.awt.Image;

import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

public class Main {
    public static BufferedImage toBufferedImage(Image image) {
        if (image instanceof BufferedImage)
            return (BufferedImage) image;

        // This code ensures that all the pixels in the image are loaded
        image = new ImageIcon(image).getImage();

        BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);
        Graphics g = bimage.createGraphics();
        g.drawImage(image, 0, 0, null);
        g.dispose();
        return bimage;
    }
}

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)