Question

I have done too much R&D on pinch zoom and found lots of example of pinch zoom for android..

How pinch zoom image in image zoom android?

android pinch zoom

But when I tried to zoom big images (ex: >10 MB, 12200x8521) then It failed to decode. But built in gallery can do and it can zoom. not even zoom but after zoom it display very clean image. While in above pichZoomView can not zoom like this..

I found QuickPic app which is having same zoom feature like gallery. I don't know how this products decode images and zoom like system gallery app.

If I decode full image then it throws OutOfMemoryException and If I decode using sampling then it makes blurred image when I zoom.

I have invested lots of time to get source code of gallery app but still I am unable to find actual gallery zoom implementation from source.Any one has solution? Or gallery source code for pinch zoom implementation.

Was it helpful?

Solution

I have invested lots of my time and got solution from here subsampling-scale-image-view.

OTHER TIPS

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);     
setContentView(R.layout.colorchart);
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
                      bmpFactoryOptions.inSampleSize =9;
                      bmpFactoryOptions.inDither=false;                     //Disable Dithering mode
                      bmpFactoryOptions.inPurgeable=true;                   //Tell to gc that whether it needs free memory, the Bitmap can be cleared
                      bmpFactoryOptions.inInputShareable=true;              //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
    //                bmpFactoryOptions.inTempStorage=new byte[102*1024*1024];
                      bmpFactoryOptions.inJustDecodeBounds = true;
                      i1=(ImageView)findViewById(R.id.thefeelingwheelclear);
                      bmp = BitmapFactory.decodeResource(getResources(),R.drawable.thefeelingwheelclear, bmpFactoryOptions);
                      Display display = getWindowManager().getDefaultDisplay();
                      int width = display.getWidth();
                      int height = display.getHeight();
                      if (bmpFactoryOptions.outWidth > width || bmpFactoryOptions.outHeight > height) {
                          float heightRatio = (float) height / (float) bmpFactoryOptions.outHeight;
                          float widthRatio = (float) width / (float) bmpFactoryOptions.outWidth;
                          // WHY
                          if(height >= 1024 )
                          {
                              heightRatio = heightRatio /1.2f;
                              widthRatio = widthRatio / 1.15f;
                         }else if(height <= 1024 && height >= 280){

                              heightRatio = heightRatio /1.45f;
                              widthRatio = widthRatio / 1.1f;

                          }else{
                              heightRatio = heightRatio /0.95f;
                              widthRatio = widthRatio / 0.8f;

                          }
                          float scale = widthRatio;          
                          float scale1 = heightRatio;
                          matrix.setScale(scale, scale1);


                      } else {
                          matrix.setTranslate(1f, 1f);
                      }

                    realBmp = BitmapFactory.decodeResource(getResources(),R.drawable.thefeelingwheelclear);
                    i1.setImageBitmap(realBmp);
                    i1.setImageMatrix(matrix);
                    i1.setOnTouchListener(this); 

    }

    @Override
           public boolean onTouch(View v, MotionEvent event) {
              ImageView view = (ImageView) v;
              view.setScaleType(ScaleType.MATRIX);
              dumpEvent(event);
              // Handle touch events here...
              switch (event.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                 savedMatrix.set(matrix);
                 start.set(event.getX(), event.getY());
                 Log.d(TAG, "mode=DRAG");
                 mode = DRAG;
                 break;
              case MotionEvent.ACTION_POINTER_DOWN:
                 oldDist = spacing(event);
                 Log.d(TAG, "oldDist=" + oldDist);
                 if (oldDist > 10f) {
                    savedMatrix.set(matrix);
                    midPoint(mid, event);
                    mode = ZOOM;
                    Log.d(TAG, "mode=ZOOM");
                 }
                 break;
              case MotionEvent.ACTION_UP:
              case MotionEvent.ACTION_POINTER_UP:
                 mode = NONE;
                 Log.d(TAG, "mode=NONE");
                 break;
              case MotionEvent.ACTION_MOVE:
                 if (mode == DRAG) {
                    // ...
                    matrix.set(savedMatrix);
                    matrix.postTranslate(event.getX() - start.x,
                          event.getY() - start.y);
                 }
                 else if (mode == ZOOM) {
                    float newDist = spacing(event);
                    Log.d(TAG, "newDist=" + newDist);
                    if (newDist > 10f) {
                       matrix.set(savedMatrix);
                       float scale = newDist / oldDist;
                       matrix.postScale(scale, scale, mid.x, mid.y);
                    }
                 }
                 break;
              }
              view.setImageMatrix(matrix);
              return true; // indicate event was handled
           }

           /** Show an event in the LogCat view, for debugging */
           private void dumpEvent(MotionEvent event) {
              String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE",
                    "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" };
              StringBuilder sb = new StringBuilder();
              int action = event.getAction();
              int actionCode = action & MotionEvent.ACTION_MASK;
              sb.append("event ACTION_").append(names[actionCode]);
              if (actionCode == MotionEvent.ACTION_POINTER_DOWN
                    || actionCode == MotionEvent.ACTION_POINTER_UP) {
                 sb.append("(pid ").append(
                       action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
                 sb.append(")");
              }
              sb.append("[");
              for (int i = 0; i < event.getPointerCount(); i++) {
                 sb.append("#").append(i);
                 sb.append("(pid ").append(event.getPointerId(i));
                 sb.append(")=").append((int) event.getX(i));
                 sb.append(",").append((int) event.getY(i));
                 if (i + 1 < event.getPointerCount())
                    sb.append(";");
              }
              sb.append("]");
              Log.d(TAG, sb.toString());
           }

           /** Determine the space between the first two fingers */
           private float spacing(MotionEvent event) {
              float x = event.getX(0) - event.getX(1);
              float y = event.getY(0) - event.getY(1);
              return FloatMath.sqrt(x * x + y * y);
           }

           /** Calculate the mid point of the first two fingers */
           private void midPoint(PointF point, MotionEvent event) {
              float x = event.getX(0) + event.getX(1);
              float y = event.getY(0) + event.getY(1);
              point.set(x / 2, y / 2);
           }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top