android 默认相机黑色,android – 相机预览仍然是黑色的
我在我的Android应用程序上尝试相机预览.当我试用我的真实设备时,它会给我黑屏.这是我的代码,它不会抛出任何错误,但屏幕仍然是黑色的.有任何想法吗?import android.app.Activity;import android.content.Context;import android.graphics.PixelFormat;import android.hardware.Camer
我在我的
Android应用程序上尝试相机预览.当我试用我的真实设备时,它会给我黑屏.
这是我的代码,它不会抛出任何错误,但屏幕仍然是黑色的.有任何想法吗?
import android.app.Activity;
import android.content.Context;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.FrameLayout;
public class ARrazerNav extends Activity{
public void onCreate(Bundle savedInstanceState){
try{
super.onCreate(savedInstanceState);
CustomCameraView cv = new CustomCameraView(this.getApplicationContext());
FrameLayout r1 = new FrameLayout(this.getApplicationContext());
setContentView(r1);
r1.addView(r1);
}catch (Exception e) {
// TODO: handle exception
}
}
public class CustomCameraView extends SurfaceView{
Camera camera;
SurfaceHolder previewHolder;
public CustomCameraView(Context ctx){
super(ctx);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
previewHolder.addCallback(surfaceHolderListener);
}
SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback(){
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
}
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
try{
camera.setPreviewDisplay(previewHolder);
}catch (Throwable th) {
// TODO: handle exception
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
Parameters params = camera.getParameters();
params.setPreviewSize(width, height);
params.setPictureFormat(PixelFormat.JPEG);
camera.setParameters(params);
camera.startPreview();
}
};
}
}
有人可以给我一些解释为什么它给我黑屏?
更多推荐
所有评论(0)