surfaceview在相机surfaceview onResume后不可见 [英] surfaceview over camera surfaceview not visible after onResume

查看:553
本文介绍了surfaceview在相机surfaceview onResume后不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的相机应用我有两个surfaceviews,一为preVIEW相机和一个画一个名为TFRAME(扩展surfaceView其类型isTarget_Frame)的形状。
在beggining它工作正常,但是onResume之后,当应用程序是不可见的,则TFRAME surfaceview是不可见的,我只查看previews相机之一。

in my camera app i have two surfaceviews, one for preview the camera and one that draws a shape called tFrame(its type isTarget_Frame that extends surfaceView). At the beggining it works correctly but after onResume when the app is not visible, the tFrame surfaceview is not visible i only view the one that previews the camera.

这是我的code

public class CameraActivity extends Activity {

private Camera mCamera;
private CameraPreview  mPreview;
public Target_Frame tFrame;
private ColorView cViewActual;
private ColorView bestMatchCView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Log.d("Function", "onCreate iniciado");
    setContentView(R.layout.camera_layout);



    tFrame=new Target_Frame(this);
    cViewActual=(ColorView)findViewById(R.id.colorViewActual);
    bestMatchCView=(ColorView)findViewById(R.id.colorViewBestMatch);



    mCamera=getCameraInstance();
    mPreview=new CameraPreview(this, mCamera,cViewActual,bestMatchCView,tFrame,colorNametextView);





    FrameLayout preview=(FrameLayout)findViewById(R.id.camera_preview);

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    params.gravity=Gravity.CENTER;

    tFrame.setLayoutParams(params);
    preview.addView(tFrame);//the first to put is the one on the bottom of the view
    preview.addView(mPreview);



}




/** Check if this device has a camera only if not specified in the manifest */
public boolean checkCameraHardware(Context context) {
    Log.d("Function", "checkCameraHardware iniciado");
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
        // this device has a camera
        return true;
    } else {
        // no camera on this device
        return false;
    }
}

/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
    Log.d("Function", "getCameraInstance iniciado");
    Camera c = null;
    try {
        c = Camera.open(); // attempt to get a Camera instance
    }
    catch (Exception e){
        // Camera is not available (in use or does not exist)
    }
    return c; // returns null if camera is unavailable
}




/**Check if the device has flash*/
public boolean checkFlash(Context context){
    Log.d("Function", "checkFlash iniciado");
    if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)){
        //the device has flash
        return true;
    }else{
        //no flash
        return false;
    }

}




@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    Log.d("Function", "onDestroy CameraActivity iniciado");
    releaseCamera();
}




@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    Log.d("Function", "onPause CameraActivity iniciado");
    releaseCamera();
}




@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    Log.d("Function", "onResume CameraActivity iniciado");
    //Test if i have to put all this code like in onCreate
    if(mCamera!=null){
        return;
    }
    mCamera=getCameraInstance();

    //if(mPreview!=null){
    //  return;
    //}

    mPreview=new CameraPreview(this, mCamera,cViewActual,bestMatchCView,tFrame,colorNametextView);
    FrameLayout preview=(FrameLayout)findViewById(R.id.camera_preview);
    preview.addView(mPreview);




}


private void releaseCamera(){
    Log.d("Function", "releaseCamera iniciado");
    if (mCamera != null){
        mCamera.setPreviewCallback(null);
        mCamera.release();        // release the camera for other applications
        mCamera = null;
    }
}

}

推荐答案

最后我deleteed第二面的观点,因为我的Adroid文档surfaceviews不作出与另一surfaceview使用在读

Finally i deleteed the second surface view because i read in adroid documentation that surfaceviews are not made to use with another surfaceview

这篇关于surfaceview在相机surfaceview onResume后不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆