0

first of all thank for your time. I have a jar library which would be included as library in my Android Application. This jar, among other things, is able to get the RGB values from a jpg image. This works perfectly in my java application but when I runs it in my Android application it does not work because the class ImageIO.read(File file) (Bufferedimage) does not implemented in Android. I read something about using Bitmap class but i do not find out anything about it.

Could you help me with this method you find here below?

public static int[][][] getImageRgb(BufferedImage image) { 
int width = image.getWidth(); 
int height = image.getHeight();
int[][][] rgb = new int[height][width][3]; 
for (int i = 0; i < height; i++) { 
for (int j = 0; j < width; j++) { 
int pixel = image.getRGB(j, i); 
rgb[i][j] = getPixelRgb(pixel); } 
} 
return rgb; 
}

Where getPixelRgb is a function aims this:

public static int[] getPixelRgb(int pixel) {
        // int alpha = (pixel >> 24) & 0xff;
        int red = (pixel >> 16) & 0xff;
        int green = (pixel >> 8) & 0xff;
        int blue = (pixel) & 0xff;
        return new int[]{red, green, blue};
}

I really I do not know how to transform this methods for Android.

I look forward to hearing from you. Thank a lot.

Paride Letizia
  • 330
  • 1
  • 4
  • 23

1 Answers1

1

What you need is in the official docs:

int getPixel (int x, int y)

Returns the Color at the specified location.

You can create a Bitmap from a resource in res/drawable folder or if you're downloading the image, you need to first save it to the device storage.

Galya
  • 6,294
  • 6
  • 27
  • 45