Java代码
  1. publicvoidonCreate(Bundleicicle){
  2. super.onCreate(icicle);
  3. LinearLayoutlinLayout=newLinearLayout(this);
  4. //加载需要操作的图片,这里是eoeAndroid的logo图片
  5. BitmapbitmapOrg=BitmapFactory.decodeResource(getResources(),
  6. R.drawable.icon);
  7. //获取这个图片的宽和高
  8. intwidth=bitmapOrg.getWidth();
  9. intheight=bitmapOrg.getHeight();
  10. //定义预转换成的图片的宽度和高度
  11. intnewWidth=200;
  12. intnewHeight=200;
  13. //计算缩放率,新尺寸除原始尺寸
  14. floatscaleWidth=((float)newWidth)/width;
  15. floatscaleHeight=((float)newHeight)/height;
  16. //创建操作图片用的matrix对象
  17. Matrixmatrix=newMatrix();
  18. //缩放图片动作
  19. matrix.postScale(scaleWidth,scaleHeight);
  20. //旋转图片动作
  21. matrix.postRotate(45);
  22. //创建新的图片
  23. BitmapresizedBitmap=Bitmap.createBitmap(bitmapOrg,0,0,width,
  24. height,matrix,true);
  25. //将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView,ImageButton中
  26. BitmapDrawablebmd=newBitmapDrawable(resizedBitmap);
  27. //创建一个ImageView
  28. ImageViewimageView=newImageView(this);
  29. //设置ImageView的图片为上面转换的图片
  30. imageView.setImageDrawable(bmd);
  31. //将图片居中显示
  32. imageView.setScaleType(ScaleType.CENTER);
  33. //将ImageView添加到布局模板中
  34. linLayout.addView(imageView,newLinearLayout.LayoutParams(
  35. LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
  36. //设置为本activity的模板
  37. setContentView(linLayout);
  38. }

更多相关文章

  1. android调用系统拍照程序和从图库选取图片,返回后调用系统裁剪工
  2. android中Intent的介绍和常见用法总结
  3. Android(安卓)BitmapFactory用法总结
  4. Android使用post方式上传图片到服务器的方法
  5. Android(安卓)网易云音乐图片高斯模糊
  6. 个性缩放图片NinePatchDrawable
  7. android桌面快捷方式创建无标题文章
  8. Android选择图片的两种方式
  9. Android(安卓)获取照相机图片或本地图片

随机推荐

  1. Android中SQLite数据库操作(2)——SQLiteOp
  2. 【Android游戏开发十五】关于Android 游
  3. Android 6.0中"Unable to find optional
  4. Android和蓝牙GPS结合的方法
  5. Android基于XMPP Smack openfire 开发的
  6. Android消息机制 空闲消息处理器
  7. Android常用UI之Toolbar
  8. android实现页面背景的左右移动
  9. android (13) Fragment使用下
  10. android 按钮 的状态