gpt4 book ai didi

java - takePicture 因堆相关错误而失败

转载 作者:搜寻专家 更新时间:2023-10-30 21:34:58 25 4
gpt4 key购买 nike

首先要注意的是:以下错误发生在 2 个不同的 HTC Desires 上,一个是 2.3.3,一个是 4.0.4。

我在尝试调用 .takePicture 时收到以下错误消息:

E/MemoryHeapBase(104): error opening /dev/pmem_camera: No such file or directory
E/QualcommCameraHardware(104): failed to construct master heap for pmem pool /dev/pmem_camera
E/QualcommCameraHardware(104): initSnapshot X failed with pmem_camera, trying with pmem_adsp

此错误后永远不会调用相应的 PictureCallback。

我能找到的唯一解释是 a) 没有调用 startPreview; b) 尝试拍照太快(在调用图片回调之前); c) 没有设置正确的使用/权限

我 a) 在这里,在我的 FullscreenActivity 的 onResume() 中:

//open the camera resource
cam = Camera.open();

Camera.Parameters params = cam.getParameters();
//change Parameters
params.setJpegQuality(100);//best quality
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
//params.setZoom(2);
List<Size> supportedPreviewSizes = cam.getParameters().getSupportedPreviewSizes();
params.setPreviewSize(supportedPreviewSizes.get(0).width, supportedPreviewSizes.get(0).height);
cam.setParameters(params);

SurfaceView sv = (SurfaceView)this.findViewById(R.id.surfaceView1);
SurfaceHolder mHolder = sv.getHolder();
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mHolder.setSizeFromLayout();
mHolder.addCallback(this);

try {
cam.setPreviewDisplay(mHolder);
} catch (IOException e) {
Log.d(TAG, "Error setting camera preview: " + e.getMessage());
}

//Log.d(TAG, "Starting Preview");
cam.startPreview();

b) 不适用于我,因为我只尝试拍一张照片

c): 使用我的 list 的一部分:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.camera.flash"/>

一些附加代码:

我调用 takePicture 的地方(请注意,此处记录意味着 AsyncTask 被允许在完成后再次调用 takePicture。无关紧要,但是因为错误仍然存​​在而从未调用 AsyncTask):

findViewById(R.id.snap_button).setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

recording = !recording;

Button btn = (Button)findViewById(R.id.snap_button);
if(recording) {
//update buttontext
btn.setText("Stop");
//start recording by taking a picture
cam.takePicture(null,null, mPicture);

} else {
//update button text
btn.setText("Start");
}

}
});

编辑:稍微改变我的布局后,终于调用了 pictureCallback 并且我得到了有效数据(是的),但是错误仍然存​​在。这是我当前的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="0dp"
android:layout_height="369dp"
android:layout_weight="1.55" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
android:id="@+id/snap_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture" />

<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>

最佳答案

我会说你在步骤中有一些错误。

你应该看看这个例子: cw-android - camera preview (第 127+ 行)。我猜你不会等到 SurfaceHolder.Callback 中的第一次 surfaceChanged,通常你应该调用 startPreview() 方法,因此你的解释

a) startPreview wasn't called;

b) trying to take pictures too fast (before the picture callback was invoked);

可能都是正确的。

关于java - takePicture 因堆相关错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14896320/

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