Zoom In & Out Custom Camera - Null Pointer Exception

后端 未结 2 2033
星月不相逢
星月不相逢 2021-01-14 10:57

I am trying to Implement Zoom In & Out functionality in my Custom Camera.

    NullPointerException: zoomControls.setVisibility(View.GONE);
相关标签:
2条回答
  • 2021-01-14 11:26

    try this code :

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub 
    
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
                mode = NONE;
                Log.d(TAG, "mode=NONE");
                break;
            case MotionEvent.ACTION_MOVE:
                if (mode == ZOOM) {
                        float newDist = spacing(event);
    
                        double zoomDist = newDist-oldDist;
    
                        if(zoomDist > 0){
                            if(zoomDist > 50 && zoomDist <= 200){
    
                                if (curZoomLevel < mZoomMax && gestureZoom == 0) {
                                    gestureZoom ++;
                                    GestureZoomIn();
                                }
    
                            }else if(zoomDist > 200 && zoomDist <= 300){
    
    
                                if (curZoomLevel < mZoomMax && gestureZoom == 1) {
    
                                    gestureZoom ++;
                                    GestureZoomIn();
                                }
                            }else if(zoomDist > 300 && zoomDist <= 400){
    
                                if (curZoomLevel < mZoomMax && gestureZoom == 2) {
    
                                    gestureZoom++;
                                    GestureZoomIn();
                                }
                break;
            }
    
            view.setImageMatrix(matrix);
            return true;
        }
    
    
     private void GestureZoomIn(){
           if (mParameters.isZoomSupported()){
                mZoomMax = mParameters.getMaxZoom();
                if (zoom_text_value<mZoomMax) {
                    zoom_text_value++;
                    curZoomLevel++;
                    zoom_float=zoom_float+0.5;
                    onZoomValueChanged(curZoomLevel);
    
    private void GestureZoomOut(){
           if (mParameters.isZoomSupported()){
    
                if (0<zoom_text_value) {
                    zoom_text_value--;
                    curZoomLevel--;
                    zoom_float=zoom_float-0.5;
                    onZoomValueChanged(curZoomLevel);
    

    this might be help you.

    0 讨论(0)
  • 2021-01-14 11:41

    In your code, params isn't ever initialized, thus its value is always null. This will result in a NullPointerException if you try to use a method on the null object. Perhaps in your constructor you should initialize it with the following:

    params = mCamera.getParameters();
    
    0 讨论(0)
提交回复
热议问题