java - 如何將一張普通圖片轉(zhuǎn)成64級(jí)灰度圖片?
問題描述
如何將一張普通圖片轉(zhuǎn)成64級(jí)灰度圖片?在Java或者Android平臺(tái)上。
問題解答
回答1:public static Bitmap convertGreyImg(Bitmap img) {int width = img.getWidth(); //獲取位圖的寬int height = img.getHeight(); //獲取位圖的高int[] pixels = new int[width * height]; //通過位圖的大小創(chuàng)建像素點(diǎn)數(shù)組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實(shí)現(xiàn)圖片相似度
回答2:去看下Android的這個(gè)類ColorMatrixAndroid的矩陣(一):ColorMatrix
相關(guān)文章:
1. 怎么php怎么通過數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。2. 求大神支招,php怎么操作在一個(gè)html文件的<head>標(biāo)記內(nèi)添加內(nèi)容?3. php - 數(shù)據(jù)庫(kù)表如果是null怎么替換為其他字段的值4. mysql - 數(shù)據(jù)庫(kù)建字段,默認(rèn)值空和empty string有什么區(qū)別 1105. 致命錯(cuò)誤: Class ’appfacadeTest’ not found6. mysql - JAVA怎么實(shí)現(xiàn)一個(gè)DAO同時(shí)實(shí)現(xiàn)查詢兩個(gè)實(shí)體類的結(jié)果集7. javascript - mysql插入數(shù)據(jù)時(shí)怎樣避免與庫(kù)中的數(shù)據(jù)重復(fù)?8. mysql建表報(bào)錯(cuò),查手冊(cè)看不懂,求解?9. shell - Update query wrong in MySQL10. sql語(yǔ)句 - 如何在mysql中批量添加用戶?
