`
韩悠悠
  • 浏览: 827540 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

android图片的旋转和缩放

 
阅读更多
使用Android中的Matrix类实现

//加载需要操作的图片
Bitmap bitmapOrg = BitmapFactory.decoreResource(getResource(),R.drawable.eoe_andrid);
//获取这个图片的宽度和高度
int width = bitmapOrg.getWidth();
int hegith = bitmapOrg.getHeight();

//定义预转化成的图片的宽度和高度
int newWidht =200;
int newHeight=200;
//计算缩放率,新尺寸除原始尺寸
float scaleWidth = ((float)newWidth)/width;
float scaleHeight= ((float)newHeight)/height;
//创建操作图片用的Matrix对象
Matrix matrix = new Matrix();
//缩放图像动作
matrix.postScale(scaleWidth,scaleHeight);
//旋转图片
matrix.postRotate(45);
创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg,0,0,width,hegith,matrix,true);
//将上面的创建的Bitmap转化成Drawable对象
BitmapDrawable bmb = new BitmapDrawable(resizedBitmap);

//创建一个imageview
ImageView imageView = new ImageView(this);
imageView.setImageDrawable(bmb);

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics