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. javascript - 能否讓vue-cli的express修改express重啟服務2. 解決Android webview設置cookie和cookie丟失的問題3. javascript - gulp打包引入文件路徑在生產環境和開發環境下的切換4. node.js - npm一直提示proxy有問題5. python - 我想把下面代碼中的多余空白行去除該怎么做,如何用正則實現6. PHP單例模式7. 最新版本的微信web開發者工具必須要APPID,會提供測試號,但是像你一樣tabBar配置的話不會顯示首頁與日志,難道我要下載跟你一樣的版本?8. 網頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應該怎么解決9. python - tweepy 庫 連接Twitter API 報錯10. python - 網頁title中包含換行,如何用正則表達式提取出來?
