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. 致命錯誤: Class ’appfacadeTest’ not found2. 怎么php怎么通過數組顯示sql查詢結果呢,查詢結果有多條,如圖。3. 老師們php,插入數據庫mysql,都是空的,要怎么解決4. php點贊一天一次怎么實現5. sql語句 - 如何在mysql中批量添加用戶?6. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語法實現存在即更新應該使用哪個標簽?7. 在應用配置文件 app.php 中找不到’route_check_cache’配置項8. PHP類屬性聲明?9. 求大神支招,php怎么操作在一個html文件的<head>標記內添加內容?10. phpstady在win10上運行
