mbitmap = BitmapFactory.decodeStream(getClass().getResourceAsStream("/res/drawable/testyuv2.bmp"));
int width = mbitmap.getWidth(); //获取位图的宽
int height = mbitmap.getHeight(); //获取位图的高
datas = new int[width * height]; //通过位图的大小创建像素点数组
mbitmap.getPixels(datas, 0, width, 0, 0, width, height);
int alpha = 0xFF << 24;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int grey = datas[width * i + j];
int red = ((grey & 0x00FF0000) >> 16);
int green = ((grey & 0x0000FF00) >> 8);
int blue = (grey & 0x000000FF);
grey = (int) ((float) red * 0.3 + (float) green * 0.59 + (float) blue * 0.11);
grey = alpha | (grey << 16) | (grey << 8) | grey;
datas[width * i + j] = grey;
}
}
android bitmap 转 灰度 byte[] 数组
最新推荐文章于 2024-07-09 21:52:34 发布