模拟器在片刻之后崩溃

时间:2016-10-18 14:58:34

标签: android camera emulation

我要做的是将一个surfaceView分配给模拟器的摄像头(我不想只是预览拍摄快照)。我已经允许在manisfest中使用cam,我让模拟器访问我的网络摄像头。该应用程序很棒,它正在做它应该做的事情但是模拟器最多会在15秒内崩溃。我的模拟器有1.5 GB的RAM,我的电脑的RAM是8 GB。

Camera mCamera;
SurfaceView mPreview;
ImageView myView;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_preview);

    mPreview = (SurfaceView)findViewById(R.id.preview);
    //myView = (ImageView)findViewById(R.id.myview);
    mPreview.getHolder().addCallback(this);
    mPreview.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mCamera = Camera.open();
  // Picasso.with(this).load("").into(myView);

}

@Override
public void onPause() {
    super.onPause();
    mCamera.stopPreview();
}

@Override
public void onDestroy() {
    super.onDestroy();
    mCamera.release();
    Log.d("CAMERA","Destroy");
}

public void onCancelClick(View v) {
    finish();
}

public void onSnapClick(View v) {
   // mCamera.takePicture(this,null, null, mPicture);
    mCamera.takePicture(this, null, null, this);


}

@Override
public void onShutter() {
    Toast.makeText(this, "Click!", Toast.LENGTH_SHORT).show();
}

@Override
public void onPictureTaken(byte[] data, Camera camera) {
    //Here, we chose internal storage
    try {
        FileOutputStream out = openFileOutput("picture.jpg", Activity.MODE_PRIVATE);
        out.write(data);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    camera.startPreview();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    Camera.Parameters params = mCamera.getParameters();
    List<Camera.Size> sizes = params.getSupportedPreviewSizes();
    Camera.Size selected = sizes.get(0);
    params.setPreviewSize(selected.width,selected.height);
    mCamera.setParameters(params);

    mCamera.setDisplayOrientation(90);
    mCamera.startPreview();
    //Picasso.with(this).load("").into(myView);

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    try {
        mCamera.setPreviewDisplay(mPreview.getHolder());
       // Picasso.with(this).load("").into(myView);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    Log.i("PREVIEW","surfaceDestroyed");
}
编辑:令人沮丧的是,android显示器没有显示任何错误

10-18 15:08:15.823 2318-2318/com.example.user.tryagain I/art: Not late-enabling -Xcheck:jni (already on)
10-18 15:08:15.847 2318-2318/com.example.user.tryagain W/System: ClassLoader referenced unknown path: /data/app/com.example.user.tryagain-1/lib/x86
10-18 15:08:19.275 2318-2318/com.example.user.tryagain W/System: ClassLoader referenced unknown path: /data/app/com.example.user.tryagain-1/lib/x86
10-18 15:08:19.418 2318-2469/com.example.user.tryagain D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                                     [ 10-18   15:08:19.422  2318: 2318 D/         ]
                                                                        HostConnection::get() New Host Connection established 0xac42ef00, tid 2318
10-18 15:08:19.474 2318-2469/com.example.user.tryagain I/OpenGLRenderer: Initialized EGL, version 1.4
10-18 15:08:19.515 2318-2469/com.example.user.tryagain W/EGL_emulation: eglSurfaceAttrib not implemented
10-18 15:08:19.516 2318-2469/com.example.user.tryagain W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa4551c0, error=EGL_SUCCESS
10-18 15:08:19.953 2318-2318/com.example.user.tryagain I/Choreographer:  Skipped 30 frames!  The application may be doing too much work on its main thread.

0 个答案:

没有答案