出现内存错误onPictureTaken BitmapFactory.decodeByteArray

时间:2013-09-13 12:23:27

标签: android bitmap camera out-of-memory

我在解码拍摄时得到的字节数时遇到了一个奇怪的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");
        }
    }
}

0 个答案:

没有答案