安卓开发-图像处理-使用Matrix操作图片

安卓开发-图像处理-使用Matrix操作图片


在Android中,通过Matrix来对图片进行缩放、旋平移等。

相关API

Matrix.postScale(float sx,float sy) //缩放

Matrix.postRotate(float degrees)//旋转

Matrix.postTranslate(float dx,float dy)//平移

Matrix.reset()//重置

ImageView.setImageMatrix(Matrix matrix)// ImageView空间设置Matrix 对象并显示

1.缩放图片

ImageView的scaleType属性要设置为“matrix”

<ImageView
        android:src="@drawable/hhh"
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="matrix"/>

使用matrix.postScale(scale_X, scale_Y)将图片进行缩放,以左上角为中心,X轴以scale_X,Y轴以scale_Y比例进行缩放。

使用imageView.setImageMatrix(matrix)重新显示缩放后的图片。

matrix.postScale(scale_X, scale_Y);
imageView.setImageMatrix(matrix);

结果展示

2.旋转图片

matrix.postRotate(degree)有两个方法,第一个是默认以左上角为中心进行图片旋转,第二个是指定像素点,并以它为中心点进行旋转

结果展示
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值