android 利用ImagevView加载本地图片并实现等比缩放
2013-01-31 10:55
846 查看
/** * 利用ImagevView加载本地图片并实现等比缩放 * * @param url * @param maxX * @param maxY * @return */ public static Bitmap zoomLocalBitmap(String url, int maxX, int maxY) { float scale; try { FileInputStream fis = new FileInputStream(url); Bitmap bitmap = BitmapFactory.decodeStream(fis); // /把流转化为Bitmap图片 int imgWidth = bitmap.getWidth(); int imgHeight = bitmap.getHeight(); if (imgWidth > maxX || imgHeight > maxY) { float scaleWidth = ((float) maxX) / imgWidth; float scaleHeight = ((float) maxY) / imgHeight; if (scaleWidth > scaleHeight) { scale = scaleWidth; } else { scale = scaleHeight; } Matrix matrix = new Matrix(); matrix.postScale(scale, scale); Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, imgWidth, imgHeight, matrix, true); return newBitmap; } else return bitmap; } catch (FileNotFoundException e) { e.printStackTrace(); return null; } }
相关文章推荐
- android中 利用缩放加载本地大图片
- Android 利用Matrix实现图片随手指平移、旋转、缩放
- Android实现图片异步加载及本地缓存
- android利用定时器实现应用开头加载图片或者静态广告的显示
- Android 使用Glide加载网络图片等比例缩放的实现方法
- Android实现网络加载图片点击大图后浏览可缩放
- android异步加载图片并缓存到本地实现方法
- android异步加载图片并缓存到本地实现方法
- Android图片异步加载与本地缓存的实现
- Android 使用Picasso加载网络图片等比例缩放的实现方法
- Android 利用Matrix实现图片的缩放查看
- Android实现本地图片选择及预览缩放效果仿春雨医生
- Android开发之图片处理专题(三):利用ThreadPoolExcutor线程池实现多图片的异步加载
- ReactNative Android 实现加载本地图片
- Android使用自定义控件实现加载本地图片无限轮播
- Android中利用Matrix实现图片平移、缩放和旋转
- Android利用缩放加载大图片避免内存溢出
- android异步加载图片并缓存到本地实现方法