【问题标题】:Get RGB of JPG in Android [duplicate]在Android中获取JPG的RGB [重复]
【发布时间】:2017-03-29 07:41:47
【问题描述】:

首先感谢您的宝贵时间。我有一个 jar 库,它将作为库包含在我的 Android 应用程序中。 除其他外,此 jar 能够从 jpg 图像中获取 RGB 值。这在我的 java 应用程序中运行良好,但是当我在我的 Android 应用程序中运行它时它不起作用,因为类 ImageIO.read(File file) (Bufferedimage) 没有在 Android 中实现。 我读过一些关于使用 Bitmap 类的内容,但我没有找到任何关于它的内容。

你能帮我看看你在下面找到的这个方法吗?

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 呢?
  • 感谢您的回复,但我真的不知道如何实现它

标签: java android bufferedimage javax.imageio mobile-development


【解决方案1】:

你需要的都在官方docs

int getPixel (int x, int y)

返回指定位置的颜色。

您可以从 res/drawable 文件夹中的资源创建位图,或者如果您正在下载图像,则需要先将其保存到设备存储中。

【讨论】:

  • 非常感谢,但我应该使用 Bitmap android 类吗?以哪种方式?
  • 我已经更新了答案。如果您提供更具体的信息,我可能会进一步帮助您。
  • 我希望你能帮助我。告诉我更多关于你想要的更多信息。我可以私信吗?
猜你喜欢
  • 2017-05-24
  • 2010-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多