0

对不起我的英语不好。

我已经写了这段代码来使用我的三星galaxy s plus上的前置摄像头。但是该应用程序打开了我的默认相机并且工作非常糟糕。我想用前置摄像头录制视频,但前置摄像头打不开。

任何想法?

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;



import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.content.Intent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;

public class Main extends Activity implements SurfaceHolder.Callback {

private static final String TAG = null;

private Camera mcamera;

private SurfaceView mSurfaceView;
private SurfaceHolder mSurfaceHolder;
private boolean mPreviewRunning;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFormat(PixelFormat.TRANSLUCENT); 
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);   //full screen
    setContentView(R.layout.main);


    mSurfaceView = (SurfaceView)findViewById(R.id.camerasurf);
    mSurfaceHolder = mSurfaceView.getHolder();  
    mSurfaceHolder.addCallback(this);   
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);    



}







public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    if (mPreviewRunning)
        mcamera.stopPreview();

    Camera.Parameters p = mcamera.getParameters();  
    p.set("camera-id", 2);
    p.setPreviewSize(640, 480); 
    mcamera.setParameters(p);   



    try {

        mcamera.setPreviewDisplay(arg0);    
        mcamera.startPreview();
        mPreviewRunning = true;
    } catch (IOException e) {

    }

}
public void surfaceCreated(SurfaceHolder holder) {

     mcamera=Camera.open();

}

public void surfaceDestroyed(SurfaceHolder holder) {
    mcamera.stopPreview();
    mPreviewRunning = false;
    mcamera.release();

}

}

在我的清单上我写了这个。

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"         android:required="false"/>
<uses-feature android:name="android.hardware.camera.front"       android:required="false"/>

我的错误在哪里?TNX

4

0 回答 0