我正在嘗試使用bitmapfactory創建位圖類。我以YUV格式獲取相機預覽圖像並手動解碼爲灰度圖像。當我嘗試通過BitmapFactory創建位圖對象時,它返回null。Android中的BitmapFactory null問題
try {
for (int y = 0; y < frameHeight; y++){
for (int x = 0; x < frameWidth; x++){
byte grey = YUVData[y * frameWidth + x];
convertedData[y * stride + 3 * x] = grey;
convertedData[y * stride + 3 * x + 1] = grey;
convertedData[y * stride + 3 * x + 2] = grey;
}
}
Bitmap bitmap =(Bitmap) BitmapFactory.decodeByteArray(convertedData, 0, convertedData.length);
類似的問題和答案: [字節數據進行圖像] [1] [1]:http://stackoverflow.com/questions/5212531/android-byte-to-image -in-camera-onpreviewframe – Kaediil