1

Here is the ZOOM IN AND ZOOM out TouchImageView.This is the code available ZOOM IN AND ZOOM OUT CUSTOM FUNCTION IN IMAGEVIEW for zoom in and zoom out it sucessfully zooming IN and zoomng OUT an image on Button click but i am failed to scroll after zoom.I have seen scrollView part here MeahdiIjaz Answer.Can Someone please adjust the part of scroll both horizontal and vertical in this TouchImageView ?

can someone please help me here TouchImage View

here is the logcat error after following "MikeOrtiz" answers whenever i am trying to zoom with my figers my application crashed user can touch the image how can i avoid from this problem? i just want to zoom via zoomin and zoomout button but if someone else touch on image then it should ignore that action instead of crashing app

02-03 21:09:00.880: E/AndroidRuntime(14290): FATAL EXCEPTION: main 02-03 21:09:00.880: E/AndroidRuntime(14290): java.lang.UnsupportedOperationException: Scale must be greater than minScale and less than maxScale 02-03 21:09:00.880: E/AndroidRuntime(14290): at com.example.imagetouchview.TouchImageView1.setZoom(TouchImageView1.java:369) 02-03 21:09:00.880: E/AndroidRuntime(14290): at com.example.imagetouchview.TouchImageView1.setZoom(TouchImageView1.java:354) 02-03 21:09:00.880: E/AndroidRuntime(14290): at com.example.imagetouchview.MainActivity$1.onClick(MainActivity.java:49) 02-03 21:09:00.880: E/AndroidRuntime(14290): at android.view.View.performClick(View.java:4211) 02-03 21:09:00.880: E/AndroidRuntime(14290): at android.view.View$PerformClick.run(View.java:17267) 02-03 21:09:00.880: E/AndroidRuntime(14290): at android.os.Handler.handleCallback(Handler.java:615) 02-03 21:09:00.880: E/AndroidRuntime(14290): at android.os.Handler.dispatchMessage(Handler.java:92) 02-03 21:09:00.880: E/AndroidRuntime(14290): at android.os.Looper.loop(Looper.java:137) 02-03 21:09:00.880: E/AndroidRuntime(14290): at android.app.ActivityThread.main(ActivityThread.java:4898) 02-03 21:09:00.880: E/AndroidRuntime(14290): at java.lang.reflect.Method.invokeNative(Native Method) 02-03 21:09:00.880: E/AndroidRuntime(14290): at java.lang.reflect.Method.invoke(Method.java:511) 02-03 21:09:00.880: E/AndroidRuntime(14290): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 02-03 21:09:00.880: E/AndroidRuntime(14290): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 02-03 21:09:00.880: E/AndroidRuntime(14290): at dalvik.system.NativeStart.main(Native Method)

Community
  • 1
  • 1
user3233280
  • 279
  • 2
  • 7
  • 21

1 Answers1

0

First, check out the code in the dev branch. Next, check out a method in TouchImageView called setZoom(). You can wire up this method to your zoom buttons like this:

zoomIn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            float scale = image.getCurrentZoom();
            PointF centerPoint = image.getCenterOfZoomedImage();
            image.setZoom(scale * 1.25, centerPoint.x, centerPoint.y);
        }
});
Mike Ortiz
  • 4,031
  • 4
  • 27
  • 54
  • is Image instance of TouchImageView ? i am getting error PointF centerPoint = touch.getCenterOfZoomedImage(); touch.setZoom(scale * 1.25,centerPoint.x,centerPoint.y); these methods are not defined in TouchImageView even i have used recent TouchimageView.java from – user3233280 Feb 03 '14 at 04:53
  • everytime i am getting this error and my application crashed whenever i am trying to touch on image and trying to zoomin with my fingers application crashed what;s the reason here is the logcat error : – user3233280 Feb 03 '14 at 05:18
  • have added logcat in Edit please see – user3233280 Feb 03 '14 at 05:21
  • 1
    Yes, image is an instance of TouchImageView. These methods are in TouchImageView, make sure you have the latest code in the dev branch, not the master branch. The logcat error above says you are setting zoom greater than maxZoom. You will need to make sure not to do that like this: `image.setZoom(Math.min(image.getMaxZoom(), scale * 1.25), centerPoint.x, centerPoint.y);` – Mike Ortiz Feb 03 '14 at 08:58
  • wao .....its working fine i have added this code in in zoomIn button may i need to add this in zoomOut button as well if yes then how? – user3233280 Feb 03 '14 at 10:24
  • i just stuck on these issues from a week and u resolved in a day thanks just let me know about zoomOut button can i limit user at specific values of zoomin and if user reached this value then i disable zoomIn button ? – user3233280 Feb 03 '14 at 10:26
  • Yes, you will need some analogous functionality in zoomOut. Instead of `Math.min`, use `Math.max`, and instead of `image.getMaxZoom()` use `image.getMinZoom()` etc. If you want to disable the button, the best place to do so would be after you setZoom in `onClick`. There, check if `image.getCurrentZoom() == image.getMaxZoom()` and if it is disable the button. But, make sure to reenable the button when the user clicks the other button! – Mike Ortiz Feb 03 '14 at 21:25