将double值(索引颜色)转换为int值 - Android

时间:2014-03-22 18:43:10

标签: android image-processing colors bitmap

我尝试显示图像时遇到问题。我有一个double值的二维数组,每个值代表RGB中的索引颜色。

我必须使用数组2D的每个值创建一个位图。我用这个配置创建了一个位图:

Bitmap bm = Bitmap.createBitmap(DIMX, DIMY, Config.RGB_565);

然后使用:

来定位位图的每个像素值
bm.setPixel(i, j, ¿?);

android文档说set像素方法的第三个参数是一个表示Color的int值。我的问题是:如何从存储在2d数组中的double值中获取int值?

1 个答案:

答案 0 :(得分:0)

你可以int type cast

Bitmap bmOut = Bitmap.createBitmap(arrayWidth, arrayHeight,
                ARGB_8888);
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                // set newly-inverted pixel to output image
                bmOut.setPixel(x, y, (int)array[x][y]);
            }
        }

bmOut是您想要的位图

相关问题