package com.huawei.mytestapp.lib;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.render.PixelMapHolder;
import ohos.agp.utils.Matrix;
import ohos.agp.utils.Point;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;
import ohos.global.resource.*;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;
import ohos.multimodalinput.event.TouchEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
/**
* 手势图片控件
*
* @author clifford
*/
public class PinchImageViewnew extends Component implements Component.DrawTask, Component.TouchEventListener, Component.DoubleClickedListener {
////////////////////////////////配置参数////////////////////////////////
/**
* 图片缩放动画时间
*/
public static final int SCALE_ANIMATOR_DURATION = 200;
/**
* 惯性动画衰减参数
*/
public static final float FLING_DAMPING_FACTOR = 0.9f;
/**
* 图片最大放大比例
*/
private static final float MAX_SCALE = 4f;
private PixelMap mp ;
private PixelMapHolder pixelMapHolder;
private TouchEvent e ;
static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG");
////////////////////////////////监听器////////////////////////////////
/**
* 外界点击事件
*
private ClickedListener mOnClickListener;
/**
* 外界长按事件
*
*/
private LongClickedListener mOnLongClickListener;
@Override
public void setClickedListener(ClickedListener l) {
//默认的click会在任何点击情况下都会触发,所以搞成自己的
// mOnClickListener = l;
}
@Override
public void setLongClickedListener(LongClickedListener l) {
//默认的long click会在任何长按情况下都会触发,所以搞成自己的
mOnLongClickListener = l;
}
////////////////////////////////公共状态获取////////////////////////////////
/**
* 手势状态:自由状态
*
* @see #getPinchMode()
*/
public static final int PINCH_MODE_FREE = 0;
/**
* 手势状态:单指滚动状态
*
* @see #getPinchMode()
*/
public static final int PINCH_MODE_SCROLL = 1;
/**
* 手势状态:双指缩放状态
*
* @see #getPinchMode()
*/
public static final int PINCH_MODE_SCALE = 2;
/**
* 外层变换矩阵,如果是单位矩阵,那么图片是fit center状态
*
*/
private Matrix mOuterMatrix = new Matrix();
/**
* 矩形遮罩
*
* @see #getMask()
*/
private RectFloat mMask;
/**
* 当前手势状态
*
* @see #getPinchMode()
* @see #PINCH_MODE_FREE
* @see #PINCH_MODE_SCROLL
* @see #PINCH_MODE_SCALE
*/
private int mPinchMode = PINCH_MODE_FREE;
/**
* 获取外部变换矩阵.
*
* 外部变换矩阵记录了图片手势操作的最终结果,是相对于图片fit center状态的变换.
* 默认值为单位矩阵,此时图片为fit center状态.
*
* @param matrix 用于填充结果的对象
* @return 如果传了matrix参数则将matrix填充后返回,否则new一个填充返回
*/
public Matrix getOuterMatrix(Matrix matrix) {
if (matrix == null) {
matrix = new Matrix(mOuterMatrix);
} else {
matrix.setMatrix(mOuterMatrix);
}
return matrix;
}
/**
* 获取内部变换矩阵.
*
* 内部变换矩阵是原图到fit center状态的变换,当原图尺寸变化或者控件大小变化都会发生改变
* 当尚未布局或者原图不存在时,其值无意义.所以在调用前需要确保前置条件有效,否则将影响计算结果.
*
* @param matrix 用于填充结果的对象
* @return 如果传了matrix参数则将matrix填充后返回,否则new一个填充返回
*/
public Matrix getInnerMatrix(Matrix matrix) {
if (matrix == null) {
matrix = new Matrix();
} else {
matrix.reset();
}
if (isReady()) {
//原图大小
RectFloat tempSrc = MathUtils.rectFTake(0,0,mp.getImageInfo().size.width,mp.getImageInfo().size.height);
//控件大小
RectFloat tempDst = MathUtils.rectFTake(0,0,getWidth(),getHeight());
//计算fit center矩阵
matrix.setRectToRect(tempSrc, tempDst, Matrix.ScaleToFit.CENTER);
//释放临时对象
MathUtils.rectFGiven(tempDst);
MathUtils.rectFGiven(tempSrc);
}
return matrix;
}
/**
* 获取图片总变换矩阵.
*
* 总变换矩阵为内部变换矩阵x外部变换矩阵,决定了原图到所见最终状态的变换
* 当尚未布局或者原图不存在时,其值无意义.所以在调用前需要确保前置条件有效,否则将影响计算结果.
*
* @param matrix 用于填充结果的对象
* @return 如果传了matrix参数则将matrix填充后返回,否则new一个填充返回
*
* @see #getOuterMatrix(Matrix)
* @see #getInnerMatrix(Matrix)
*/
public Matrix getCurrentImageMatrix(Matrix matrix) {
//获取内部变换矩阵
matrix = getInnerMatrix(matrix);
//乘上外部变换矩阵
matrix.postConcat(mOuterMatrix);
return matrix;
}
/**
* 获取当前变换后的图片位置和尺寸
*
* 当尚未布局或者原图不存在时,其值无意义.所以在调用前需要确保前置条件有效,否则将影响计算结果.
*
* @param RectFloat 用于填充结果的对象
* @return 如果传了RectFloat参数则将RectFloat填充后返回,否则new一个填充返回
*
* @see #getCurrentImageMatrix(Matrix)
*/
public RectFloat getImageBound(RectFloat RectFloat) {
if (RectFloat == null) {
RectFloat = new RectFloat();
} else {
RectFloat.clear();
}
if (!isReady()) {
return RectFloat;
} else {
//申请一个空matrix
Matrix matrix = MathUtils.matrixTake();
//获取当前总变换矩阵
getCurrentImageMatrix(matrix);
//对原图矩形进行变换得到当前显示矩形
RectFloat.modify(0, 0,mp.getImageInfo().size.width,mp.getImageInfo().size.height);
matrix.mapRect(RectFloat);
//释放临时matrix
MathUtils.matrixGiven(matrix);
return RectFloat;
}
}
/**
* 获取当前设置的mask
*
* @return 返回当前的mask对象副本,如果当前没有设置mask则返回null
*/
public RectFloat getMask() {
if (mMask != null) {
return new RectFloat(mMask);
} else {
return null;
}
}
/**
* 获取当前手势状态
*
* @see #PINCH_MODE_FREE
* @see #PINCH_MODE_SCROLL
* @see #PINCH_MODE_SCALE
*/
public int getPinchMode() {
return mPinchMode;
}
/**
* 与ViewPager结合的时候使用
* @param direction
* @return
*/
/**
* 与ViewPager结合的时候使用
* @param direction
* @return
*/
// @Override
// public boolean canScrollVertically(int direction) {
// if (mPinchMode == PinchImageView.PINCH_MODE_SCALE) {
// return true;
// }
// RectFloat bound = getImageBound(null);
// if (bound == null) {
// return false;
// }
// if (bound.isEmpty()) {
没有合适的资源?快使用搜索试试~ 我知道了~
基于开源项目AndroidPinchImageView进行鸿蒙化的移植和开发的
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共29个文件
xml:7个
java:6个
gitignore:3个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 10 浏览量
2023-05-06
14:21:17
上传
评论
收藏 118KB ZIP 举报
温馨提示
本项目是基于开源项目AndroidPinchImageView进行鸿蒙化的移植和开发的,可以通过项目标签以及github地址追踪到原安卓项目版本。imageview控件,鸿蒙的第三方组件适配移植,实现了对图片的手势放大缩小,平移等功能
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rtf](https://img-home.csdnimg.cn/images/20210720083624.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 29 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/de50ac10e30e41b89db28203f97239be_qq_41701956.jpg!1)
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6835
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)