CODE

    public Bitmap ToGrayBitmap(byte[] rawValues, int width, int height) throws Exception {
        // 申请目标位图的变量,并将其内存区域锁定
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        int index;
        int color;
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                index = y * width + x;
                color = getUnsignedByte(rawValues[index]);
                // bmp.setPixel(x, y, color <= 150 ? 0xFF000000 : 0xFFFFFFFF);
                bmp.setPixel(x, y, 0xFF000000 | (color << 16) | (color << 8) | color);
            }
        }
        

        // 算法到此结束,返回结果
        return bmp;
    }

 

posted @ 2014-05-14 16:08  crowinhell  阅读(144)  评论(0编辑  收藏  举报