1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 彩色照片转化为黑白照片

彩色照片转化为黑白照片

时间:2019-11-14 10:11:38

相关推荐

彩色照片转化为黑白照片

/*** 将彩色图转换为纯黑白二色** @param bmp 位图* @return 返回转换好的位图*/public static Bitmap convertToBlackWhite(Bitmap bmp) {int width = bmp.getWidth(); // 获取位图的宽int height = bmp.getHeight(); // 获取位图的高int[] pixels = new int[width * height]; // 通过位图的大小创建像素点数组bmp.getPixels(pixels, 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 = pixels[width * i + j];//分离三原色int red = ((grey & 0x00FF0000) >> 16);int green = ((grey & 0x0000FF00) >> 8);int blue = (grey & 0x000000FF);//转化成灰度像素grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);grey = alpha | (grey << 16) | (grey << 8) | grey;pixels[width * i + j] = grey;}}//新建图片Bitmap newBmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);//设置图片数据newBmp.setPixels(pixels, 0, width, 0, 0, width, height);Bitmap resizeBmp = ThumbnailUtils.extractThumbnail(newBmp, 380, 460);return resizeBmp;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。