当前位置: 代码迷 >> Android >> android图片的旋转跟缩放
  详细解决方案

android图片的旋转跟缩放

热度:101   发布时间:2016-05-01 19:47:56.0
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);//创建一个imageviewImageView imageView = new ImageView(this);imageView.setImageDrawable(bmb);

?

  相关解决方案