我在解码拍照时得到的字节数组时遇到了一个奇怪的 OOM 错误。我的代码如下。请告诉是否有更好的方法来做到这一点。
@Override
public void onPictureTaken(byte[] data, Camera camera) {
// TODO something with the image data
// Restart the preview and re-enable the shutter button so that we can take another picture
camera.startPreview();
inPreview = true;
shutterButton.setEnabled(true);
System.gc();
Bitmap bitmap = BitmapFactory.decodeByteArray(data , 0, data.length);
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, false);
if(bitmap != null){
boolean fileSaved = Funcs.saveImage(getActivity(),resizedBitmap, "moizali");
if(fileSaved){
((BaseActivity)getActivity()).goToPhotoEditActivity("moizali");
}
}
}