0

i am newbie in android.Here is the already asked question in SO Scrolling and zoomin and Zoomout Issue now this issue resolved.This is the latest version of File Latest Version with zoom and scrolling but every time i am getting this error of

 02-03 21:21:08.030: E/AndroidRuntime(17110): java.lang.UnsupportedOperationException: Scale must be greater than minScale and less than maxScale

whenever i am trying to touch image using fingers it throws an exception and my application crashed.Same is the case when trying to continuously click zoomin and zoomout buttton i want behaviour of this image zoom in and zoom out just like webview.i dnt want to set any limitations in this functionality.how can i resolve this error of touch and iamgeScale settings .Please help me.

MainActivity.java:

 public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                  setContentView(R.layout.newxml);
        ImageView zoonIn = (ImageView)findViewById(R.id.btn_zoomIn1);
        ImageView zoonOut = (ImageView)findViewById(R.id.btn_zoomout1);

        final TouchImageView1 touch = (TouchImageView1)findViewById(R.id.imagezoom);

        Bitmap bImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.app_icon);

        touch.setImageBitmap(bImage);
        touch.setMinZoom(0.5f);
        touch.setMaxZoom(5f);

        zoonIn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                 float scale = touch.getCurrentZoom();
                 PointF centerPoint = touch.getCenterOfZoomedImage();
                Number zoomedValue =scale*1.25;
                        float value = zoomedValue.floatValue();
                touch.setZoom(value,centerPoint.x,centerPoint.y);
            }
        });


        zoonOut.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                 float scale = touch.getCurrentZoom();
                 PointF centerPoint = touch.getCenterOfZoomedImage();
                    Number zoomedValue =scale/1.25;
                       float value = zoomedValue.floatValue();
                    touch.setZoom(value,centerPoint.x,centerPoint.y);
                }

        });

    }
}

Logcat Error:

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

Community
  • 1
  • 1
user3233280
  • 279
  • 2
  • 7
  • 21
  • in your activity, which are the lines 369 and 364? , also can debug and check the values that you are getting in onclick listeners or just post a log for the values. Also, try https://github.com/chrisbanes/PhotoViewhttps://github.com/chrisbanes/PhotoView , if it suits your requirement – Pararth Feb 03 '14 at 06:14
  • public void setZoom(float scale, float focusX, float focusY, ScaleType scaleType) { if (scale < minScale || scale > maxScale) { throw new UnsupportedOperationException("Scale must be greater than minScale and less than maxScale"); } if (focusX < 0 || focusX > 1 || focusY < 0 || focusY > 1) { throw new UnsupportedOperationException("focusX and focusY must range in value between 0 and 1"); } – user3233280 Feb 03 '14 at 06:18
  • setScaleType(scaleType); resetZoom(); scaleImage(scale, viewWidth / 2, viewHeight / 2, false); matrix.getValues(m); m[Matrix.MTRANS_X] = -((focusX * getImageWidth()) - (viewWidth * 0.5f)); m[Matrix.MTRANS_Y] = -((focusY * getImageHeight()) - (viewHeight * 0.5f)); matrix.setValues(m); setImageMatrix(matrix); }this is line 369 and i am getting same exception as it has been written here – user3233280 Feb 03 '14 at 06:18
  • check what is the value for zoomed value and its float after : zoomedValue =scale*1.25; float value = zoomedValue.floatValue(); need to re-evaluate either float scale = touch.getCurrentZoom(); PointF centerPoint = touch.getCenterOfZoomedImage(); or the min/max zoom values – Pararth Feb 03 '14 at 06:23
  • this is value and after that my app crashed : 02-03 22:23:16.980: I/zoomedValue(11244): 5.9604644775390625 02-03 22:23:16.980: I/Value(11244): 5.9604645 – user3233280 Feb 03 '14 at 06:30
  • i guess i need to set zoomin and zoomout values minimum and maximum and on zoomin button click i need to check if maz zoom == my zoom value then button should be disabled else button will be enabled – user3233280 Feb 03 '14 at 06:32
  • it'l help you if you do not 'guess' what you need to set :) , check my answer. Study your usecase(s) and set it with a more precise idea of min/max and centerPoint value. – Pararth Feb 03 '14 at 06:39

1 Answers1

0

Obvious now: Your zoom value is larger than the maxZoom you set.
5.9604645.
Try setting maxZoom to 6f. You need to consider your usecase properly before setting the min/max zoom values.
Also need to consider the different behaviours and its corresponding values you would get in:

float scale = touch.getCurrentZoom();
PointF centerPoint = touch.getCenterOfZoomedImage();

I suggest you go through what can fit in your requirement and have a look at: https://github.com/chrisbanes/PhotoView
I have used that and it is quite simple and transparent in terms of its library classes too.

Pararth
  • 8,114
  • 4
  • 34
  • 51
  • can i do zoomin and out on button click using mentioend library if yes please give me any sample project – user3233280 Feb 03 '14 at 06:39
  • It'l be better to, at least, check the link i have provided. Yes you can implement zoom and seems correct for what you require here. Need to study things through, you can get the sample app and more info from that link also. – Pararth Feb 03 '14 at 06:42