Java Image to BufferedImage getBufferedImage(Image image)

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

Description

Creates and returns a buffered version of the specified image.

License

Open Source License

Parameter

Parameter Description
image the image to create a buffered image for

Return

a buffered image based on the specified image

Declaration

public static BufferedImage getBufferedImage(Image image) 

Method Source Code

//package com.java2s;
/**/*  w  ww . ja  va  2 s .  c  om*/
 * Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://robocode.sourceforge.net/license/epl-v10.html
 */

import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    /**
     * Creates and returns a buffered version of the specified image.
     *
     * @param image the image to create a buffered image for
     * @return a buffered image based on the specified image
     */
    public static BufferedImage getBufferedImage(Image image) {
        BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufferedImage.getGraphics();

        g.drawImage(image, 0, 0, null);

        return bufferedImage;
    }
}

Related

  1. bufferedImageFromImage(final Image image)
  2. convertToBufferedImage(Image image)
  3. getBufferedImage(Image image)
  4. getBufferedImage(Image image)
  5. getBufferedImage(Image image)
  6. getBufferedImage(Image img)
  7. getBufferedImage(java.awt.Image image)
  8. getScaledBufferedImage(Image icon, double scale)