本文介绍了Camera.set previewDisplay()抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/7942378/android-camera-will-not-work-start$p$pview-fails">Android相机将无法正常工作。 p $ PVIEW失败启动$

我想设置一个摄像头preVIEW在自定义的SurfaceView但每次我执行初始化方法时,我得到一个例外。

I am trying to set a camera preview in a custom SurfaceView but I get an exception each time I execute the initialization method.

下面是code相机preVIEW初始化:

Below is the code for camera preview initialization:

private void init(Context context)
{
    setFocusable(true);
    mRecording = false;
    fileRW = new FileReaderWriter();
    frameCount = 0;
    if(mCamera == null)
    {
        mCamera = Camera.open();
    }
    Parameters parameters = mCamera.getParameters();
    parameters.setPictureFormat(PixelFormat.JPEG);
    mCamera.setParameters(parameters);
    try {
        mCamera.setPreviewDisplay(surfaceHolder);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mCamera.startPreview();

}

mCamera.set previewDisplay(surfaceHolder); 抛出异常(设置previewDisplay失败)每次我试图执行的方法。

the line mCamera.setPreviewDisplay(surfaceHolder); throws an exception (setPreviewDisplay failed) each time I try to execute the method.

有谁知道什么可能是错误的?我真的AP preciate您的帮助。

Does anyone know what could be wrong? I would really appreciate any of your help.

谢谢!`

推荐答案

我完全乔恩明亮同意

我无法弄清楚发生了什么事情了一个星期,我忽略了的setType的表面支架,因为SDK说,这是pcated德$ P $,即

I couldn't figure out what was going on for a week, I ignored the setType on the surface holder because the SDK said it was deprecated, ie.

此方法pcated德$ P $。此被忽略,该值在需要时自动设定。

但是,如果你不这样做,它会崩溃的一套preVIEW。这是在Galaxy S的运行1.5 SDK(我需要它是向后兼容的)2.1。因此,请确保您设置的类型。不太自动为文档,使得它听起来。

But if you don't do that, it will crash on setPreview. This is running 1.5 SDK (I need it to be backwards compatible to that) on a Galaxy S with 2.1. So make sure you set the type. Not quite as automatic as the documentation makes it sound.

这篇关于Camera.set previewDisplay()抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 00:52