rawData
我从库函数中获取类型为byte[]
RGBA、大小为 640x480、每像素 4 个字节的原始相机数据。我需要将其转换为位图并显示在屏幕上的 ImageView 中。
我要做的是:
byte[] JPEGData = convertToJpeg(rawData, 640, 480, 80);
Bitmap bitmap = BitmapFactory.decodeByteArray(JPEGData , 0, JPEGData .length);
imageView.setImageBitmap(bitmap);
其中convertToJpeg()
函数是:
public static byte[] convertToJpeg(byte[] buffer, int w, int h, int quality) {
YuvImage yuv_image = new YuvImage(buffer, ImageFormat.NV21, w, h, null);
Rect rect = new Rect(0, 0, w, h);
ByteArrayOutputStream output_stream = new ByteArrayOutputStream();
yuv_image.compressToJpeg(rect, quality, output_stream);
Bitmap sourceBmp = BitmapFactory.decodeByteArray(output_stream.toByteArray(), 0, output_stream.size());
Bitmap destBmp = Bitmap.createScaledBitmap(sourceBmp, (int) (w * 0.75), (int) (h * 0.75), true);
ByteArrayOutputStream pictureStream = new ByteArrayOutputStream();
destBmp.compress(CompressFormat.JPEG, quality, pictureStream);
byte[] pictureByteArray = pictureStream.toByteArray();
return pictureByteArray;
}
打电话后decodeByteArray()
我有bitmap.getConfig() == ARGB_8888
。
然而,我在屏幕上看到的是一些混乱的画面,原始画面中有一些模糊的绿色形状。
它出什么问题了?