Java takePicture失败,出现与堆相关的错误

Java takePicture失败,出现与堆相关的错误,java,android,android-camera,Java,Android,Android Camera,第一件事:以下错误发生在两个不同的HTC愿望上,一个是2.3.3,一个是4.0.4 尝试呼叫时,我收到以下错误消息。拍摄照片: 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/QualcommC

第一件事:以下错误发生在两个不同的HTC愿望上,一个是2.3.3,一个是4.0.4

尝试呼叫时,我收到以下错误消息。拍摄照片:

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)在这里,在我的全屏活动的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();
编辑: 在稍微改变布局之后,pictureCallback最终被调用,我得到了有效数据(yay),但是错误仍然存在。以下是我当前的布局:

<?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>

我想说您在步骤中有一些错误

您应该看看这个示例: (第127行+)。我猜您不会等到第一次在
SurfaceHolder.Callback中
surfacechange
,通常您应该在这里调用
startPreview()
方法,从而解释

a) startPreview没有被调用

b) 尝试拍照太快(在调用图片回调之前)


可能两者都正确。

您解决了问题吗?执行此代码时是否安装了SD卡?我正在将我拍摄的照片保存到SD卡上,这样人们就会认为它已正确安装。我刚刚尝试了卸载和重新安装,但错误消息仍然存在。我认为关键错误是第三个错误,它说在找不到pmem_摄像头后,它会切换到pmem_adsp,这可能会成功。我不知道为什么pmem_摄像头没有在您的系统上初始化。这就是我目前正在做的,错误消息仍然存在。过早调用startPreview会导致另一个错误,我相信您可以附加完整的代码。我可以用安卓2.3.3测试我的HTC Desire,所以如果消息持续出现,我们可以消除硬件或供应商问题:)
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");
        }

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