1

我在捏缩放方面做了太多的研发,发现了很多安卓捏缩放的例子。

如何在图像缩放android中捏缩放图像?

安卓捏缩放

但是当我尝试放大大图像(例如:> 10 MB,12200x8521)时,它无法解码。但是内置画廊可以做到并且可以缩放。甚至没有缩放,但缩放后它显示非常干净的图像。而在上面 pichZoomView 不能像这样缩放..

我发现QuickPic应用程序具有与图库相同的缩放功能。我不知道这个产品如何像系统图库应用一样解码图像和缩放。

如果我解码完整图像,那么它会抛出OutOfMemoryException,如果我使用采样解码,那么当我缩放时它会产生模糊图像。

我已经投入了大量时间来获取画廊应用程序的源代码,但我仍然无法从源代码中找到实际的画廊缩放实现。有人有解决方案吗?或用于捏缩放实现的画廊源代码。

4

2 回答 2

2

我投入了大量时间并从这里subsampling-scale-image-view获得了解决方案。

于 2013-11-25T14:24:32.987 回答
0
    @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);
           }
于 2013-11-06T07:18:09.920 回答