Android相机预览不起作用(HTC MyTouch 3G Slide Android 2.2)

| 我的工作看不到任何问题,但是无法将手机上的相机初始化并开始绘制预览。我创建了一个非常简化的应用程序,该应用程序出现了相同的问题,如下所示:
package com.ct;

import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class TestActivity extends Activity implements SurfaceHolder.Callback {
    SurfaceHolder cameraPreviewHolder;
    Camera camera;
    SurfaceView cameraPreview;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        cameraPreview = (SurfaceView) findViewById(R.id.SurfaceCamera);
        cameraPreviewHolder = cameraPreview.getHolder();
        cameraPreviewHolder.addCallback(this);
    }
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        camera = Camera.open();
        camera.unlock();
        Parameters p = camera.getParameters();

        List<Size> sizes = p.getSupportedPreviewSizes();
        int bestFit=0;
        int difference = Integer.MAX_VALUE;
        for(int i=0; i<sizes.size(); i++){
            Size s = sizes.get(i);
            int dif = (width-s.width)+(height-s.height);
            if(s.width<=width && s.height<=height && dif>0 && dif < difference){
                bestFit = i;
                difference = dif;
            }
        }
        Size s = sizes.get(bestFit);

        p.setPreviewSize(s.width, s.height);
        p.setPictureFormat(PixelFormat.JPEG);
        camera.setParameters(p);


        try {
            camera.setPreviewDisplay(cameraPreviewHolder);
            camera.startPreview();
        } catch (IOException e) {

        }
    }
    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

    }
    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

    }
}
我的logcat显示以下内容:
W/CameraSwitch( 2020): open main camera
W/CameraSwitch( 2020): no file - can\'t switch camera
E/QualcommCameraHardware( 68): native_access_parm: error (No such file or directory): fd 14, type 1, length 32, status 0
E/mm-camera 7x-vfe( 68): Received VFE start ACK!!! This is a user preview start.
E/CameraService( 68): registerBuffers failed with status -38
W/dalvikvm( 2020): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
W/InputConnectionWrapper.ICC(  176): Timed out waiting on IInputContextCallback
有想法吗?我昨天刚刚更新到Android 2.2,希望这不会破坏我的相机API ...     
已邀请:
查看SDK随附的APIDemos / graphics / CameraPreview。 亚历克斯 更新:也尝试从PixelFormat更改为ImageFormat。我注意到这是在2.2中引入的     

要回复问题请先登录注册