有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Android中获得JPG的RGB

首先感谢您抽出时间。我有一个jar库,它将作为库包含在我的Android应用程序中。 这个jar能够从jpg图像中获取RGB值。这在我的java应用程序中非常有效,但当我在Android应用程序中运行它时,它不起作用,因为类ImageIO.read(File file)(BuffereImage)没有在Android中实现。 我读了一些关于使用位图类的内容,但没有发现任何关于它的内容

你能帮我找到下面这个方法吗

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

我期待着收到你的来信。 非常感谢


共 (0) 个答案