旋转操作中在图像周围放置一些指示器

旋转操作中在图像周围放置一些指示器

本文介绍了在图像移动/调整大小/旋转操作中在图像周围放置一些指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想缩放,移动,调整图像大小.我想用指示器包围图像,这些指示器可以指导用户这些指示器执行什么操作,即移动,旋转,缩放.

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

我尝试过

  • 缩放-但只会缩小.没有机会增加图像的长度和高度.
  • 旋转-通过插入手动角度来实现.这不是一个很好的选择.
  • 移动-当我在Api上实现阻力时< 11.一点点困难.这里仍然没有希望.

有没有可以对我进行简单图像编辑[移动,缩放,旋转]的库?

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

推荐答案

使用库: StickerView

Using Library : StickerView

它是一个第三方图书馆,提供了我一直在寻找的东西.

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

WorkAround:

这些答案仍然是我在OP中要求的一半.意味着它并没有被某些特定的指标所取代.我仍在搜索如何用指示符包装ImageView并将其用于Translate&调整大小.

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.

Activity内部变量的初始化对Translate&调整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-Matrix


Setting ImageView to scaleType - Matrix

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

iv.setOnTouchListener(t);


将onTouch Listener添加到使用


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