我正在尝试这样做,我正在从NV21字节格式的摄像头获取数据流,我可以将其转换为位图,并以png格式显示,但是我想将其与音频一起实时显示,该怎么办?
private CameraProxy.CameraDataCallBack callBack = new CameraProxy.CameraDataCallBack() {
@Override
public void onDataBack(byte[] data, long length) {
// TODO Auto-generated method stub
Log.i(TAG, "length . " + length);
//NV21 -> yuvImage -> jpeg -> bitmap
YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, realPreviewSize.getWidth(), realPreviewSize.getHeight(), null);
ByteArrayOutputStream os = new ByteArrayOutputStream();
yuvImage.compressToJpeg(new Rect(0, 0, realPreviewSize.getWidth(), realPreviewSize.getHeight()), 100, os);
byte[] jpegByteArray = os.toByteArray();
Bitmap bitmap = BitmapFactory.decodeByteArray(jpegByteArray, 0, jpegByteArray.length);
try {
fos = new FileOutputStream(photo);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
try {
fos.close();
Bitmap img = BitmapFactory.decodeFile(photo.getAbsolutePath());
runOnUiThread(new Runnable() {
@Override
public void run() {
im.setImageBitmap(img);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
};