您的位置:首页 > 其它

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

2017-12-14 09:47 1606 查看
本篇文章是对使用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;
}


实例:

private Bitmap mFaceBitmap;


Bitmap mCacheBitmap = null;


mFaceBitmap = convert(mCacheBitmap);


public static Bitmap convert(Bitmap a) {
int w = a.getWidth();
int h = a.getHeight();
//    Bitmap newb = Bitmap.createBitmap(w, h, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
//    Canvas cv = new Canvas(newb);
Matrix m = new Matrix();
// m.postScale(1, -1); //镜像垂直翻转
if (Common.ismirror) {
m.postScale(-1, 1); // 镜像水平翻转
}
m.postRotate(Common.realAngle); // 旋转-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, w, h), null);
return new2;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: