Android- Rotate image with single finger gesture

后端 未结 2 1430
小蘑菇
小蘑菇 2020-12-29 17:23

I want to know about How to rotate the bitmap image with single touch gestures.kindly help and suggest some solutions. I done scaling the bitmap with the help of

h

相关标签:
2条回答
  • 2020-12-29 17:46

    Check out my blogspot in which i have tried to implement the functionality of stretch the image on arrow click and also delete it, and also you can move the image on the screen using gesture.

    Drag-Drop image Also check out the Demo of DragDropImage

    enter image description here

    0 讨论(0)
  • 2020-12-29 17:58

    function that handles rotation with one finger, the main idea is to calculate the centerX and centerY of your view and taking into consideration the status bar height if you using one.

           @Override
           public boolean onTouch(View view, MotionEvent event) { 
             switch (action) {
                    case MotionEvent.ACTION_UP:
                        break;
                    case MotionEvent.ACTION_DOWN:
    
                        rotateX = event.getRawX();
                        rotateY = event.getRawY();
    
                        centerX = view.getX() + ((View) getParent()).getX() + (float) view.getWidth() / 2;
    
                        centerY = view.getY() + statusBarHeight + (float) view.getHeight() / 2;
    
                        break;
    
                    case MotionEvent.ACTION_MOVE:
    
                        newRotateX = event.getRawX();
                        newRotateY = event.getRawY();
    
                        double angle = Math.atan2(event.getRawY() - centerY, event.getRawX() - centerX) * 180 / Math.PI;
    
                        view.setRotation((float) angle - 45);
    
                        rotateX = newRotateX;
                        rotateY = newRotateY;
    
                }
            }
    
            return true;
        }
    };
    
    0 讨论(0)
提交回复
热议问题