gpt4 book ai didi

android - 在 Android 中使用相机拍照时出现致命信号 11 和奇怪的错误消息

转载 作者:太空狗 更新时间:2023-10-29 15:01:17 25 4
gpt4 key购买 nike

我正在尝试用相机拍照,修改拍摄的图像,然后在用户单击接受后将相机中修改后的图像显示给用户。这是我的代码,上面有一条评论,我在其中进行了代码更改,导致了此错误:

  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)

最佳答案

最初的答案没有产生我期望的正确位图输出,所以我更改了这部分:

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);
}

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

关于android - 在 Android 中使用相机拍照时出现致命信号 11 和奇怪的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26433302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com