Android大图片加载处理
16lz
2022-05-29
BitmapFactory.Options options=new BitmapFactory.Options();//创建权利 //先不计算内存 options.inJustDecodeBounds=true; BitmapFactory.decodeResource(getResources(),R.mipmap.bitmap,options); //调用Options方法来获取图片宽高 int outHeight = options.outHeight; int outWidth = options.outWidth; Log.d(TAG,"outHeight == >"+outHeight); Log.d(TAG,"outWidth == >"+outWidth); //拿控件的尺寸 int measuredHeight = result_image.getMeasuredHeight(); int measuredWidth = result_image.getMeasuredWidth(); Log.d(TAG,"measureHeight ==>"+measuredHeight); Log.d(TAG,"measureWidth ==>"+measuredWidth); //默认不改变大小 options.inSampleSize=1; //图片的宽度/控件的宽度 //图片的高度/控件的高度 //取两者间的最小值 if (outHeight>measuredHeight||outWidth>measuredWidth){ int subHeight = outHeight / measuredHeight; int subWidth = outWidth / measuredWidth; options.inSampleSize=subHeight>subWidth?subWidth : subHeight;// } options.inJustDecodeBounds=false;//可以设置进去了 Log.d(TAG,"options.inSampleSize==>"+options.inSampleSize); //根据控件大小,动态计算sample值 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.bitmap, options); result_image.setImageBitmap(bitmap);
更多相关文章
- android中TextView嵌套在ScrollView中并自由滚动
- Android(安卓)NullPointerException at android.text.BoringLayo
- android常用控件
- Android(安卓)图片缩放实例详解
- Android圆角图片封装类(直接使用)
- android旋转图片
- android获取图库图片并返回
- android WebView 拍照上传图片兼容
- Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片