15

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;        

}
humandroid
  • 311
  • 1
  • 3
  • 12

4 Answers4

4

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

Zoe
  • 27,060
  • 21
  • 118
  • 148
Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
1

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

Joe Plante
  • 6,308
  • 2
  • 30
  • 23
1
     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

urveshpatel50
  • 1,675
  • 16
  • 35
  • Can I use getRGB() , getAlpha() , getWidth(), getType() methods with Bitmap. – humandroid Nov 01 '12 at 18:57
  • yes you can do all operation on bitmap even you can getRGB value in bitmap. http://stackoverflow.com/questions/5669501/how-to-get-rgb-values-of-bitmap-in-android – urveshpatel50 Nov 01 '12 at 19:04
  • I have Edited my question. Added a function using BufferedImage. I need to change it to Bitmap and Please note that I need ImageIO for ImageIO.read(); method and ImageIO.write(); – humandroid Nov 01 '12 at 19:12
  • first read this http://stackoverflow.com/questions/5392695/bufferedimage-in-android you can not use bufferedimage – urveshpatel50 Nov 01 '12 at 19:16
0

Try with BitmapFactory or Bitmap

http://developer.android.com/reference/android/graphics/BitmapFactory.html http://developer.android.com/reference/android/graphics/Bitmap.html

biju
  • 11
  • 4
    Those links may answer the question, but it would be better if you could add the important parts from those links in your answer – maybe a short example on how to use the BitmapFactory. One day those links may no longer work and then this answer would be useless. – GameDroids Nov 06 '14 at 13:02