0

I have implemented the cameraview (import com.commonsware.cwac.camera.CameraView) with CWAC-camera, I want to switch to using CWAC-Cam2, as I do to make this migration, I no longer find the CameraHost or CameraHostProvider. As I can use the camera of CWAC-Cam2 in my interface in my activity.

I could not do this :'(

excuse me bad English, THANKS!

so I'm using this moment:

 import com.commonsware.cwac.camera.CameraHost;
import com.commonsware.cwac.camera.CameraHostProvider;
import com.commonsware.cwac.camera.CameraView;
import com.commonsware.cwac.camera.PictureTransaction;
import com.commonsware.cwac.camera.SimpleCameraHost;


public class MainActivity extends BaseActivity implements CameraHostProvider
        {


    @InjectView(R.id.cameraView)
    CameraView cameraView;


    @Override
    protected void onResume()
    {
        super.onResume();
        cameraView.onResume();
        //initCamera(varCamera,1);
    }



    @Override
    protected void onPause()
    {
             super.onPause();
             cameraView.onPause();
    }



            @Override
            public CameraHost getCameraHost() {

                return myCameraHost=new MyCameraHost(this);
            }

            class MyCameraHost extends SimpleCameraHost {

                private Camera.Size previewSize;

                public MyCameraHost(Context ctxt) {
                    super(ctxt);
                }

                @Override
                public boolean useFullBleedPreview() {
                    return true;
                }

                @Override
                public Camera.Size getPictureSize(PictureTransaction xact, Camera.Parameters parameters) {
                    return previewSize;
                }

                @Override
                public Camera.Parameters adjustPreviewParameters(Camera.Parameters parameters) {
                    Camera.Parameters parameters1 = super.adjustPreviewParameters(parameters);

                    previewSize = parameters1.getPreviewSize();
                    return parameters1;
                }

                @Override
                public void saveImage(PictureTransaction xact, final Bitmap bitmap) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            showTakenPicture(bitmap);
                        }
                    });
                }

                @Override
                public void saveImage(PictureTransaction xact, byte[] image) {
                    super.saveImage(xact, image);
                    photoPath = getPhotoPath();
                }
            }


            private void showTakenPicture(Bitmap bitmap) {
                vUpperPanel.showNext();
                vLowerPanel.showNext();
                newImage=bitmap;
                ivTakenPhoto.setImageBitmap(bitmap);
                updateState(STATE_SETUP_PHOTO);
            }

        }

1 Answers1

0

I want to switch to using CWAC-Cam2

That is not going to be practical, particularly in your case.

CWAC-Cam2 is designed to fill the same role that I had envisioned CWAC-Camera would fill: make it easier to use the camera APIs rather than have to depend upon unreliable ACTION_IMAGE_CAPTURE/ACTION_VIDEO_CAPTURE implementations.

However, the API for CWAC-Cam2 is completely different. Anyone who used CameraView, as you did, will be better served just working with the camera APIs directly.

CWAC-Cam2's API is closer to being a drop-in replacement for ACTION_IMAGE_CAPTURE and ACTION_VIDEO_CAPTURE. If you worked with CameraFragment previously, maybe you can move over to CWAC-Cam2 without as much issue, though I doubt it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491