Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using BufferedImage and ImageIO classes in my Android Activity

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;        

}
like image 732
humandroid Avatar asked Nov 01 '12 18:11

humandroid


3 Answers

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

like image 68
Konstantin Pribluda Avatar answered Oct 19 '22 23:10

Konstantin Pribluda


I think a few Java libraries aren't in Android like the awt

like image 35
Joe Plante Avatar answered Oct 20 '22 00:10

Joe Plante


     String selectedImagePath;
     ImageView img;
     img = (ImageView)findViewById(R.id.ImageView1);
     Bitmap  yourSelectedImage = BitmapFactory.decodeFile(selectedImagePath);
     img.setImageBitmap(yourSelectedImage);

if multiple image than you can make

        ArrayList<Bitmap> aList = new ArrayList<Bitmap> ();
        aList.add(yourbitmap);

than set in imageviews like above using for loop. because android not provide BufferedImage class

like image 1
urveshpatel50 Avatar answered Oct 20 '22 00:10

urveshpatel50