Android缩放图片Bitmap、Drawable
16lz
2021-01-23
Android缩放bitmap是开发应用时常常使用的,对于Drawable可以先转换为bitmap再进行缩放<pre name="code" class="java"><pre name="code" class="java">/** * Drable转为Bitmap * @author YOLANDA * @param d * @return */public static Bitmap getDrawable2Bitmap(Drawable d){BitmapDrawable bd = (BitmapDrawable) d;Bitmap bm = bd.getBitmap();return bm;}
/** * 缩放图片 * @author YOLANDA * @Time 2014年8月27日 上午11:32:21 * @param paramBitmap 原图 * @param newWidth 新的宽度 * @param newHeight 新的高度 * @return */public static Bitmap getScaleBitmap2Bitmap(Bitmap paramBitmap, int newWidth, int newHeight) {int i = paramBitmap.getWidth();int j = paramBitmap.getHeight();float f1 = ((float)newWidth) / i;float f2 = ((float)newHeight) / j;if (f1 <= 0.0F) {f1 = 1.0F;}if (f2 <= 0.0F) {f2 = 1.0F;}Matrix localMatrix = new Matrix();localMatrix.postScale(f1, f2);return Bitmap.createBitmap(paramBitmap, 0, 0, i, j, localMatrix, true);}
更多相关文章
- android通过读取系统属性设置字体缩放的默认值
- Android 图片拖动和缩放
- 补间动画--缩放动画XML
- android多点触摸缩放图片
- android imageVIew拖动 && 图片缩放
- android 两点缩放图片
- Android 缩放、移动、旋转View相关方法
- android 多点触摸实现图片缩放