Java Utililty Methods Image to BufferedImage

List of utility methods to do Image to BufferedImage

Description

The list of methods to do Image to BufferedImage are organized into topic(s).

Method

BufferedImagetoBufferedImage(Image image)
to Buffered Image
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
boolean hasAlpha = hasAlpha(image);
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
int transparency = Transparency.OPAQUE;
...
BufferedImagetoBufferedImage(Image image)
Given an image, produces a BufferedImage
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
boolean hasAlpha = hasAlpha(image);
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
...
BufferedImagetoBufferedImage(Image image)
This method returns a buffered image with the contents of an image.
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
boolean hasAlpha = hasAlpha(image);
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
...
BufferedImagetoBufferedImage(Image image)
Returns a buffered image with the contents of an image Adapted from: http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
boolean hasAlpha = hasAlpha(image);
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
...
BufferedImagetoBufferedImage(Image image)
to Buffered Image
if (image == null)
    return null;
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
if (image.getWidth(null) < 0 || image.getHeight(null) < 0) {
    image = new ImageIcon(image).getImage();
int imgType = hasAlpha(image) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
BufferedImage buffImg = new BufferedImage(image.getWidth(null), image.getHeight(null), imgType);
Graphics g = buffImg.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return buffImg;
BufferedImagetoBufferedImage(Image image)
to Buffered Image
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
    int transparency = Transparency.OPAQUE;
...
BufferedImagetoBufferedImage(Image image)
This method returns a buffered image with the contents of an image.
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
boolean hasAlpha = hasAlpha(image);
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
...
BufferedImagetoBufferedImage(Image image)
to Buffered Image
if (image instanceof BufferedImage)
    return (BufferedImage) image;
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();
...
BufferedImagetoBufferedImage(Image image)
Converts an AWT Image into a BufferedImage.
if (image instanceof BufferedImage) {
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
boolean hasAlpha = hasAlpha(image);
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
...
BufferedImagetoBufferedImage(Image image)
to Buffered Image
if (image instanceof BufferedImage)
    return (BufferedImage) image;
image = new ImageIcon(image).getImage();
int type = hasAlpha(image) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
Graphics g = bimage.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
...