首先感谢您的时间。我有一个jar库,将作为库包含在我的Android应用程序中。 除此之外,这个jar能够从jpg图像中获取RGB值。这在我的Java应用程序中完美工作,但是当我在Android应用程序中运行它时,它不起作用,因为类ImageIO.read(File file)
(Bufferedimage)未在Android中实现。 我读了一些关于使用Bitmap类的东西,但我没有找到任何关于它的东西。在Android中获取RGB的JPG
你能帮我解决这个问题吗?
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;
}
凡getPixelRgb是一个函数的目的是:
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};
}
我真的不知如何改造这个方法适用于Android。
我期待着您的回音。 非常感谢。
什么?真的吗? [this]怎么样(https://developer.android.com/reference/android/graphics/Bitmap.html)? – Blackbelt
谢谢你的回应,但是我真的不知道如何实现它 –