Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load BufferedImage in android?

I want to load BufferedImage in my application. For that I am using ImageIO but I am getting java.lang.NoClassDefFoundError:

BufferedImage tgtImg = loadImage("ImageD2.jpg"); 
public static BufferedImage loadImage(String ref) { 
    BufferedImage bimg = null; 
    try { 
        bimg = ImageIO.read(new File(ref)); 
    } catch (Exception e) { 
        e.printStackTrace(); 
    } 
    return bimg; 
}

but i am getting exception:

03-15 18:05:22.051: ERROR/AndroidRuntime(437): java.lang.NoClassDefFoundError: javax.imageio.ImageIO
like image 253
Monali Avatar asked Mar 15 '11 11:03

Monali


People also ask

How do I change an image to BufferedImage?

BufferedImage buffer = ImageIO. read(new File(file)); to Image i.e in the format something like : Image image = ImageIO.

What does BufferedImage mean?

A BufferedImage is comprised of a ColorModel and a Raster of image data. The number and types of bands in the SampleModel of the Raster must match the number and types required by the ColorModel to represent its color and alpha components. All BufferedImage objects have an upper left corner coordinate of (0, 0).

What is the difference between BufferedImage and image?

A BufferedImage is essentially an Image with an accessible data buffer. It is therefore more efficient to work directly with BufferedImage. A BufferedImage has a ColorModel and a Raster of image data. The ColorModel provides a color interpretation of the image's pixel data.


1 Answers

ImageIO is not supported in Android SDK

Could you achieve the same thing with Bitmap and BitmapFactory?? like so...

Bitmap tgtImg = BitmapFactory.decodeFile("ImageD2.jpg");

if tgtImg is not null after this then it was successful.

like image 91
Will Tate Avatar answered Oct 31 '22 13:10

Will Tate