在Android中用相机拍照时的致命信号11和奇怪的错误信息

时间:2014-10-17 20:54:09

标签: android camera crash sigsegv renderscript

我正在尝试用相机拍照,修改拍摄的图像,然后在用户点击接受后将相机中的修改后的图像显示给用户。这是我的代码,上面有一条注释,我做了代码更改,产生了这个错误:

  private class TakePictureThread extends Thread {
    private Camera.PictureCallback pPictureCallback;

    @Override
    public void run() {

        pPictureCallback = new PictureCallback() {

            @Override
            public void onPictureTaken(byte[] data, Camera camera) {

                CameraInfo info = new CameraInfo();
                Camera.getCameraInfo(0, info);

                SurfaceView surfaceView = mCameraCaptureView.getSurfaceView();

                // TODO: scale this such that we don't need to scale the cropped image
                Bitmap unrotatedRawImage =
                        ImageUtils.decodeSampledBitmap(data,
                                surfaceView.getWidth(),
                                surfaceView.getHeight(), Bitmap.Config.RGB_565);
                Bitmap rawImage =
                        ImageHelper.rotate(unrotatedRawImage, info.orientation);
                unrotatedRawImage.recycle();

                mCroppedImage = cropRawCapturedImage(rawImage);
                rawImage.recycle();

                mCroppedImage = Bitmap.createScaledBitmap(
                        mCroppedImage,
                        ImageSize.CARD.getPixelWidth(),
                        ImageSize.CARD.getPixelHeight(),
                        false);

                mImagePreview.setImageBitmap(mCroppedImage);

                if (useBlurringAndGradient()) {
                    //new code
                    Bitmap blurredBitmap = ImageUtils.blurImage(mCroppedImage);
                    mImagePreview.setImageBitmap(blurredBitmap);
                }

                handlePhotoTaken();
            }
        };

        mCameraCaptureView.getCamera().takePicture(null, null, pPictureCallback);
    }
}

blurImage方法:

/**
 * Performs the max blur possible 20 times on the bitmap provided.
 */
static private Bitmap blurCardImage(Bitmap bitmap) {
    RenderScript rs = RenderScript.create(MainApp.getInstance());

    Bitmap blurredBitmap =
            Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

    for (int i = 0; i < 20; i++) {
        Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
        Allocation allOut = Allocation.createFromBitmap(rs, blurredBitmap);

        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blurScript.setRadius(25.f);

        blurScript.setInput(allIn);
        blurScript.forEach(allOut);

        allOut.copyTo(blurredBitmap);

        bitmap = blurredBitmap;
    }

    rs.destroy();

    return bitmap;
}

以下是发生这种情况时的日志:

10-20 10:20:15.588: E/Camera(18230): Unknown message type 62273
10-20 10:20:15.588: E/Camera(18230): Unknown message type 62274
10-20 10:20:21.468: D/ProgressBar(18230): updateDrawableBounds: left = 0
10-20 10:20:21.468: D/ProgressBar(18230): updateDrawableBounds: top = 0
10-20 10:20:21.468: D/ProgressBar(18230): updateDrawableBounds: right = 228
10-20 10:20:21.468: D/ProgressBar(18230): updateDrawableBounds: bottom = 228
10-20 10:20:22.408: D/dalvikvm(18230): GC_FOR_ALLOC freed 11182K, 19% free 55902K/68748K, paused 47ms, total 47ms
10-20 10:20:22.418: V/RenderScript(18230): 0x7b761008 Launching thread(s), CPUs 4
10-20 10:20:22.428: V/RenderScript(18230): User-backed allocation failed stride requirement, falling back to separate allocation
10-20 10:20:22.498: A/libc(18230): Fatal signal 11 (SIGSEGV) at 0x7d9d7000 (code=1), thread 18869 (.myapp)
10-20 10:20:22.498: A/libc(18230): Fatal signal 11 (SIGSEGV) at 0x7d9d7000 (code=1), thread 18867 (.myapp)
10-20 10:20:22.498: A/libc(18230): Fatal signal 11 (SIGSEGV) at 0x7d9d7000 (code=1), thread 18868 (.myapp)
10-20 10:20:22.498: A/libc(18230): Fatal signal 11 (SIGSEGV) at 0x7d9d7000 (code=1), thread 18870 (.myapp)

1 个答案:

答案 0 :(得分:0)

原始答案没有产生我期待的正确位图输出所以我改变了这一部分:

if (useBlurringAndGradient()) {
    Bitmap blurredBitmap = ImageUtils.blurImage(mCroppedImage);
    mImagePreview.setImageBitmap(blurredBitmap);
}

到此:

if (useBlurringAndGradient()) {
    mImagePreview.buildDrawingCache();
    Bitmap bitmap = mImagePreview.getDrawingCache();
    Bitmap blurredBitmap = ImageUtils.blurImage(bitmap);
    mImagePreview.setImageBitmap(blurredBitmap);
}

这也修复了我遇到的崩溃,我不再在日志中看到警告。有谁知道这可以解决我的问题吗?