如何显示图像RGB值的直方图?

Use*_*501 2 java android image graph histogram

我的应用程序捕获图像并对其应用滤镜以修改图像RGB值.

修改后,我希望在图像本身的顶部显示每种颜色(红色,绿色,蓝色)的直方图.

我已经知道如何获取RGB值,我已经知道如何获取Bitmap,我只是不知道如何绘制它们.

RGB值的代码:

    int[] pixels = new int[width*height];
    int index = 0;
    image.getPixels(pixels, 0, width, 0, 0, width, height);
    Bitmap returnBitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            A = (pixels[index] >> 24) & 0xFF;
            R = (pixels[index] >> 16) & 0xFF;
            G = (pixels[index] >> 8) & 0xFF;
            B = pixels[index] & 0xFF;
                            ++index;

                     }
            }
Run Code Online (Sandbox Code Playgroud)

Mal*_*aKa 5

我们做了类似的事情.我们得到了图像的位图:

Bitmap bmp = BitmapFactory.decodeResource(<youImageView>.getResources(), R.drawable.some_drawable);
Run Code Online (Sandbox Code Playgroud)

然后我们迭代每个Pixel并使用下面的代码来获得像素的颜色:

int color = bmp.getPixel(i, j);
int[] rgbValues = new int[]{
                (color >> 16) & 0xff, //red
                (color >>  8) & 0xff, //green
                (color      ) & 0xff  //blue
            };
Run Code Online (Sandbox Code Playgroud)

编辑:
我刚刚读到你也可以使用这个insead来获得不透明度:

int color = bmp.getPixel(i, j);
int[] rgbValues = new int[]{
                (color >> 24) & 0xff, //alpha
                (color >> 16) & 0xff, //red
                (color >>  8) & 0xff, //green
                (color      ) & 0xff  //blue
            };
Run Code Online (Sandbox Code Playgroud)

如果你已经有了这些值,我建议你使用androidplot来创建图形.有一些例子使它易于使用.我没有使用条形图,但折线图工作得很好.以下是androidplot的BarCharts示例.
我只想总结不同的值,然后(如果你想)将其标准化.


要最终显示图形,您可以将布局创建为FrameLayout,然后可以帮助您处理z顺序.您现在唯一需要做的就是显示/隐藏布局的一部分,包含您的图形.(View.setVisibility)