转自:http://www.eoeandroid.com/redirect.php?tid=308&goto=lastpost

public void onCreate(Bundle icicle) {super.onCreate(icicle);LinearLayout linLayout = new LinearLayout(this);// 加载需要操作的图片,这里是eoeAndroid的logo图片Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.icon);// 获取这个图片的宽和高int width = bitmapOrg.getWidth();int height = bitmapOrg.getHeight();// 定义预转换成的图片的宽度和高度int newWidth = 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,height, matrix, true);// 将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);// 创建一个ImageViewImageView imageView = new ImageView(this);// 设置ImageView的图片为上面转换的图片imageView.setImageDrawable(bmd);// 将图片居中显示imageView.setScaleType(ScaleType.CENTER);// 将ImageView添加到布局模板中linLayout.addView(imageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));// 设置为本activity的模板setContentView(linLayout);}

2

更多相关文章

  1. android读取图片
  2. Android 使用Glide实现圆形和圆角图片
  3. 2012-7-20 android 图片叠加效果——两种方法
  4. Android文件图片上传的详细讲解(四)---服务端编码
  5. android处理大图片内存溢出的简单办法
  6. android:ImageView选择本地图片并显示
  7. android获取图片和视频的缩略图

随机推荐

  1. Android(安卓)Mouse实现过程笔记
  2. Android(安卓)android-common 工具
  3. Android(安卓)双击返回键退出应用
  4. Android(安卓)中状态栏(屏幕顶部)消息的
  5. Android升级到2.3之后遇到的问题
  6. Android(安卓)Studio 1.0 安装遇到问题总
  7. Android电池架构分析(转)
  8. android点击事件的传递机制
  9. android checkbox样式
  10. android studio 真机调试连接时候好好的,