如何使用Matrix对bitmap的旋转与镜像水平垂直翻转
时间:2020-11-16 12:08:19|栏目:Android代码|点击: 次
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;
}
{
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;
}
栏 目:Android代码
下一篇:Android 自定义view实现进度条加载效果实例代码
本文标题:如何使用Matrix对bitmap的旋转与镜像水平垂直翻转
本文地址:http://www.codeinn.net/misctech/23196.html