通过把一些指标围绕移动图像

通过把一些指标围绕移动图像

本文介绍了图片缩放,旋转,通过把一些指标围绕移动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向规模化,移动,缩放图片。我想用来包围图像指标,引导用户什么操作这些指标完成,即移动,旋转,缩放。

I would like to Scale, Move, Resize Image. I would like to surrond the image with Indicators which guide user what operation these indicators perform i.e. Moving, Rotating, Scaling.

我试过

  • 在缩放 - 但它只是作物下来。没有机会,以增加长度的图像和高度。
  • 旋转 - 实现,但通过插入手动度。 That'z不是在这里一个不错的选择。
  • 动 - 因为我实现拖累阿比<困难11.所以一点。不过在这里没有希望。

有没有可以做我的简单的图像编辑任何库[移动,缩放,旋转] ??

Is there any library which can do me simple image edit [Move, Scale, Rotate]??

任何帮助,将AP preciated !!

Any Help would be appreciated!!

推荐答案

使用库: StickerView

Using Library : StickerView

它是一个第三方库赋予正是我所期待的。

Its a 3rd Party Library which gives exactly what i was looking for.

解决方法:

不过,这些答案是什么,我要求在OP一半。意味着它不是由一些具体的指标surronded。我还在寻找如何包装的ImageView 与指标,并将其用于翻译和放大器;调整大小。

Still these answer is half of what I've asked for in OP. Means It ain't surronded by some specific Indicator. I'm still searching how to wrap ImageView with indicators and use them for Translate & Resize.

动初始化里面活动的翻译和放大器重要;调整的ImageView

Initilization of Variables inside Activity important for Translate & Resize ImageView

public static final int DRAG = 1;
public static final int NONE = 0;
private static final String TAG = "Touch";
public static final int ZOOM = 2;
public static PointF mid = new PointF();
public static int mode = 0;
float d = 0.0F;
Matrix savedMatrix = new Matrix();
Matrix matrix = new Matrix();
PointF start = new PointF();


的ImageView

设置为scaleType - 矩阵

iv = new ImageView(this);
iv.setPadding(10, 10, 25, 25);
iv.setScaleType(ImageView.ScaleType.MATRIX);

iv.setOnTouchListener(t);


添加onTouch监听器的ImageView ,它使用


Adding onTouch Listener to ImageView which uses

  • 1手指翻译 - 拖
  • 2手指缩放 - 调整{捏放大}

  • 1 Finger for Translate - Drag
  • 2 Finger for Zoom - Resize {Pinch To Zoom}

View.OnTouchListener t = new View.OnTouchListener()
{
public boolean onTouch(View paramView, MotionEvent event)
{
  ImageView view = (ImageView)paramView;
  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_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;

  case MotionEvent.ACTION_UP:
  case MotionEvent.ACTION_POINTER_UP:

      mode = NONE;
      Log.d(TAG, "mode=NONE" );
      break;
  }
  view.setImageMatrix(matrix);
  return true;

}

 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);
}

      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);
      }
     };

这篇关于图片缩放,旋转,通过把一些指标围绕移动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:13