Glide图片旋转与放大缩小
最近在项目中有用Glide去显示图片,其中有去实现图片旋转和当大缩小的功能,这里分享一下
图片的旋转:
首先通过一个类继承实现BitmapTransformation
public class RotateTransformation extends BitmapTransformation {private float rotateRotationAngle = 0f;public RotateTransformation(float rotateRotationAngle) {this.rotateRotationAngle = rotateRotationAngle;}@Overrideprotected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {Matrix matrix = new Matrix();matrix.postRotate(rotateRotationAngle);return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);}@Overridepublic void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {}
}
然后通过glide去实现旋转功能:
float rotateRotationAngle = 90f;/*** 旋转图片*/private void RorateImage() {((PhotoPlayActivity) getActivity()).rotatePhoto(copeBitmap, rotateRotationAngle);rotateRotationAngle += 90f;if (rotateRotationAngle > 360f) {rotateRotationAngle = 90f;}}
public void rotatePhoto(Bitmap bitmap, float rotateRotationAngle) {Glide.with(this).load(bitmap).apply(RequestOptions.bitmapTransform(new RotateTransformation(rotateRotationAngle))).into(imageView);
}
图片的方法和缩小:
public void zoomPhoto(Bitmap bitmap, int weight, int height) {Glide.with(getApplicationContext()).asBitmap().load(resource).apply(RequestOptions.overrideOf(weight, height).centerCrop()).into(imageView);}});
}
private int mDeviceWidth;//设备原始宽
private int mDeviceHeight;//设备原始高
private int mZoomInWidth; //缩放后的高
private int mZoomInHeight;//缩放后的宽
double x = 0.8;缩小倍数
double y = 1.25; 放大倍数protected void initData() {mDeviceWidth = Utils.getDeviceWidth(MmpApplication.getApplication());//通过工具类去得到设备的宽和高,这里工具类就不展示了mDeviceHeight = Utils.getDeviceHeight(MmpApplication.getApplication());mZoomInHeight = mDeviceHeight;mZoomInWidth = mDeviceWidth;
}
/*** 缩小图片*/
private void ZoomInImage() {mZoomInWidth = (int) (mZoomInWidth * x);mZoomInHeight = (int) (mZoomInHeight * x);DebugLog.i("mZoomInWidth:" + mZoomInWidth + "mZoomInHeight:" + mZoomInHeight);if (mZoomInWidth <= mDeviceWidth && mZoomInHeight <= mDeviceHeight) {((PhotoPlayActivity) getActivity()).zoomPhoto(Bitmap, mZoomInWidth, mZoomInHeight);}
}
/*** 放大照片*/
private void ZoomOutImage() {mZoomInHeight = (int) (mZoomInHeight * y);mZoomInWidth = (int) (mZoomInWidth * y);DebugLog.i("mZoomInWidth:" + mZoomInWidth + "mZoomInHeight:" + mZoomInHeight);if (mZoomInWidth <= mDeviceWidth && mZoomInHeight <= mDeviceHeight) {((PhotoPlayActivity) getActivity()).zoomPhoto(Bitmap, mZoomInWidth, mZoomInHeight);} else {mZoomInHeight = (int) (mZoomInHeight * x);mZoomInWidth = (int) (mZoomInWidth * x);}
}
到此,就实现了图片的旋转和放大缩小功能。
Glide图片旋转与放大缩小相关推荐
- CSS3实现旋转与放大缩小
CSS3实现旋转与放大缩小 开发工具与关键技术:Abobe Dreamweaver 动画旋转与放大缩小 作者:李国旭 撰写时间:2019年1月26日 一. 我们来简单认识一下动画,动画是使元素从一种样 ...
- android+放大缩小图片+有jar嘛,Android相册支持点击放大图片,滑动切换图片,手势放大缩小...
[实例简介] 项目使用了开源框架Universal-Image-Loader 显示本地图库所有照片 点击放大,单击退出 双击放大缩小 支持左右滑动查看图片 支持手势放大缩小图片 [实例截图] [核心代 ...
- VUE图片预览放大缩小插件viewer
VUE图片预览放大缩小插件viewer 一.安装依赖 npm install v-viewer --save 二.main.js内引用并注册调用 //main.js import Viewer fro ...
- css3旋转带放大缩小效果
下载地址 css3旋转带放大缩小效果,鼠标悬停的时候触发放大或缩小并旋转的动画. dd:
- Unity触摸屏幕 拖拽物体 旋转物体 放大缩小物体 单击 双击 长按
Unity触摸屏幕 拖拽物体 旋转物体 放大缩小物体 单击 双击 长按 拖拽物体 using System.Collections; using System.Collections.Generic; ...
- Android开发--Matrix(一)--实现图片的动态放大缩小
Matrix ,中文里叫矩阵,高等数学里有介绍,在图像处理方面,主要是用于平面的缩放.平移.旋转等操作. 首先介绍一下矩阵运算.加法和减法就不用说了,太简单了,对应位相加就好.图像处理,主要用到的是 ...
- layer.photos 相册旋转与放大缩小
1.相册旋转: 图层中新增一个旋转按钮 layer.photos({photos: window['attach_albumlist'],anim: 5, //0-6的选择,指定弹出图片动画类型,默认 ...
- 我的Android进阶之旅------android Matrix图片随意的放大缩小,拖动(转)
step1:新建一个项目DragAndZoom,并准备一张照片放在res/drawable-hdpi目录下,如下图所示: step2: 设置应用的UI界面,在main.xml中设置: [html] v ...
- android 图片手动放大,Android图片的手动放大缩小
利用缩放因子进行图片的放大缩小,效果图如下 在实现过程中如出现直接崩溃的情况:在全局配置文件中加入android:largeHeap="true"即可解决问题,在文章最后有现成代码 ...
最新文章
- 阿里首次公开量子通信技术 为20年后做准备
- MarkMonitor 目前最安全的域名注册商,因此,世界500强网站中的22%域名托管于markmonitor公司...
- python怎么下载-如何下载python包
- 快排堆排归排三种排序的比较
- apache限制php上传大小修改
- python3 re模块_python3+ 模块学习 之 re
- 判断客户端是否安装FlashPlayer及版本
- jsp+servlet+jdbc实现对数据库的增删改查
- 易筋SpringBoot 2.1 | 第十篇:SpringBoot使用thymeleaf入门
- SRMD:Learning a Single Convolutional Super-Resolution Network for Multiple Degradations
- 前端需要学python吗_python是前端语言吗
- 【多元统计分析】01.多元统计的基础
- k8s1.18-kubeadm安装手册
- python制作web网页实例_基于python实现简单网页服务器代码实例
- Win10系统安装Ubuntu系统
- Java的文件读写操作
- shark恒破解笔记5-VB之rtcMsgBox
- 慎用!3个容易被打的Python恶搞脚本!
- R_Studio(关联)对Groceries数据集进行关联分析
- 1079: PIPI的存钱罐