如何使用Matrix对bitmap的旋转与镜像水平垂直翻转

2019/7/7 20:18:15

本文主要是介绍如何使用Matrix对bitmap的旋转与镜像水平垂直翻转,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Bitmap convert(Bitmap a, int width, int height)
{
int w = a.getWidth();
int h = a.getHeight();
Bitmap newb = Bitmap.createBitmap(ww, wh, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
Canvas cv = new Canvas(newb);
Matrix m = new Matrix();
m.postScale(1, -1);   //镜像垂直翻转
m.postScale(-1, 1);   //镜像水平翻转
m.postRotate(-90);  //旋转-90度
Bitmap new2 = Bitmap.createBitmap(a, 0, 0, w, h, m, true);
cv.drawBitmap(new2, new Rect(0, 0, new2.getWidth(), new2.getHeight()),new Rect(0, 0, ww, wh), null);
return newb;
}


这篇关于如何使用Matrix对bitmap的旋转与镜像水平垂直翻转的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程