Java BufferedImage to RGB imageToRgbaBufferedImage(final Image image)

Here you can find the source of imageToRgbaBufferedImage(final Image image)

Description

Convert Image to BufferedImage.

License

Apache License

Parameter

Parameter Description
image Image to be converted to BufferedImage.

Return

BufferedImage corresponding to provided Image.

Declaration

public static BufferedImage imageToRgbaBufferedImage(final Image image) 

Method Source Code

//package com.java2s;
/*//from   w w  w.j a va  2s .  c  o m
 * Copyright 2009-2016 DigitalGlobe, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 *
 */

import java.awt.*;

import java.awt.image.*;

public class Main {
    /** 
     * Convert Image to BufferedImage. 
     * 
     * @param image Image to be converted to BufferedImage. 
     * @return BufferedImage corresponding to provided Image. 
     */
    public static BufferedImage imageToRgbaBufferedImage(final Image image) {
        //    final BufferedImage bufferedImage =  
        //        new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);  

        final BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
                BufferedImage.TYPE_4BYTE_ABGR);
        final Graphics2D g2 = bufferedImage.createGraphics();
        g2.drawImage(image, 0, 0, null);
        g2.dispose();
        return bufferedImage;
    }
}

Related

  1. getRgbFromImage(BufferedImage image)
  2. getRGBPixels(BufferedImage img)
  3. imageToMatrix(BufferedImage image)
  4. imageToPixels(BufferedImage image)
  5. imageToRGBABuffer(BufferedImage img)