使用Matrix放大或缩小图片
2014-12-13 11:28
232 查看
今天在工程中需要用到图片做标注,发现给定的图片宽高有点大,本来想再截一张小图片,太麻烦。
发现可以用代码自定义放大缩小图片,然后就试着做了一下,效果还不错。
下面贴一下我的代码:
1、从工程的资源文件中读取一张图片
发现可以用代码自定义放大缩小图片,然后就试着做了一下,效果还不错。
下面贴一下我的代码:
1、从工程的资源文件中读取一张图片
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.custom_info_bubble);2、计算bitmap的宽和高
int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight();3、设置图片缩小的比例
double scale = 0.5;4、计算出这次要缩小的比例
float scaleWidth = (float) (1 * scale); float scaleHeight = (float) (1 * scale);5、使用Matrix产生缩小后的Bitmap对象
Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight,matrix, true);
相关文章推荐
- 使用Matrix放大或缩小图片
- android-Matrix放大缩小图片
- Android开发--Matrix(一)--实现图片的动态放大缩小
- HTML5:使用Canvas和Input range控件放大缩小图片
- 图片放大缩小(和ViewPager配合使用流畅显示)--第三方开源--PhotoView
- 图片放大缩小(和ViewPager配合使用流畅显示)--第三方开源--PhotoView
- android图片缩小和放大Matrix
- android Matrix图片随意的放大缩小,拖动
- android Matrix图片随意的放大缩小,拖动
- 使用Axure图片放大缩小,渐进效果
- android Matrix图片随意的放大缩小,拖动,翻页(续)
- 使用HTML5 canvas做地图(3)图片加载平移放大缩小
- 我的Android进阶之旅------>android Matrix图片随意的放大缩小,拖动
- android 图片随意的放大缩小拖动利用Matrix
- 动态放大缩小ImageView里的图片……运用Matrix对象来缩放图片文件
- Android利用Matrix实现图片的放大,缩小以及移动控制
- Android学习篇章10-Matrix图片放大缩小
- 使用HTML5 canvas做地图(3)图片加载平移放大缩小
- hammer使用: 代码:捏合、捏开、图片放大 的一个手机图片“放大缩小可拖动”的小效果
- 使用HTML5 canvas做地图(3)图片加载平移放大缩小