java - 如何將一張普通圖片轉成64級灰度圖片?
問題描述
如何將一張普通圖片轉成64級灰度圖片?在Java或者Android平臺上。
問題解答
回答1:public static Bitmap convertGreyImg(Bitmap img) {int width = img.getWidth(); //獲取位圖的寬int height = img.getHeight(); //獲取位圖的高int[] pixels = new int[width * height]; //通過位圖的大小創建像素點數組img.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 original = pixels[width * i + j];int red = ((original & 0x00FF0000) >> 16);int green = ((original & 0x0000FF00) >> 8);int blue = (original & 0x000000FF);int grey = (int) ((float) red * 0.3 + (float) green * 0.59 + (float) blue * 0.11);grey = alpha | (grey << 16) | (grey << 8) | grey;pixels[width * i + j] = grey; }}Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);result.setPixels(pixels, 0, width, 0, 0, width, height);return result; }
參考資料:Android實現圖片相似度
回答2:去看下Android的這個類ColorMatrixAndroid的矩陣(一):ColorMatrix
相關文章:
1. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?2. java - spring boot 如何打包成asp.net core 那種獨立應用?3. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?4. datetime - Python如何獲取當前時間5. docker start -a dockername 老是卡住,什么情況?6. javascript - nginx反向代理靜態資源403錯誤?7. docker網絡端口映射,沒有方便點的操作方法么?8. 安全性測試 - nodejs中如何防mySQL注入9. javascript - 關于apply()與call()的問題10. python - 調用api輸出頁面,會有標簽出現,請問如何清掉?
