Using BufferedImage and ImageIO classes in my Android Activity

humandroid picture humandroid · Nov 1, 2012 · Viewed 19.6k times · Source

I am developing an Android App that can do Gamma correction of an image stored in phone. My activity can get the image location, but i cant use the BufferedImage class and ImageIO class in my Application.

I get the following error in Eclipse IDE with ADT plugin..

 ImageIO cannot be Resolved

 BufferedImage cannot be Resolved  

I cannot process the image . I have an idea of including the java libraries but i don't know how to do this in Android

Here is the Function i need to make it work .

private static BufferedImage gammaCorrection(BufferedImage original, double gamma) {

    int alpha, red, green, blue;
    int newPixel;

    double gamma_new = 1 / gamma;
    int[] gamma_LUT = gamma_LUT(gamma_new);

    BufferedImage gamma_cor = new BufferedImage(original.getWidth(), original.getHeight(), original.getType());

    for(int i=0; i<original.getWidth(); i++) {
        for(int j=0; j<original.getHeight(); j++) {

            // Get pixels by R, G, B
            alpha = new Color(original.getRGB(i, j)).getAlpha();
            red = new Color(original.getRGB(i, j)).getRed();
            green = new Color(original.getRGB(i, j)).getGreen();
            blue = new Color(original.getRGB(i, j)).getBlue();

            red = gamma_LUT[red];
            green = gamma_LUT[green];
            blue = gamma_LUT[blue];

            // Return back to original format
            newPixel = colorToRGB(alpha, red, green, blue);

            // Write pixels into image
            gamma_cor.setRGB(i, j, newPixel);

        }

    }

    return gamma_cor;        

}

Answer

Konstantin Pribluda picture Konstantin Pribluda · Nov 1, 2012

Android is not standard java, it lacks certain classes. AWT is just not there