Android 获取图片真实宽高
2016-06-29 16:38
453 查看
Resources res = mContext.getResources(); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, R.drawable.home_common_icon_default, opts); opts.inSampleSize = 1; opts.inJustDecodeBounds = false; int w = opts.outWidth; int h = opts.outHeight; LogUtil.e("+++++++++++++++++++++++++++++++++++++++++++++++++:"); LogUtil.e("w:" + w); LogUtil.e("h:" + h); int width = DensityUtil.dip2px(mContext, w / 2); int height = DensityUtil.dip2px(mContext, h / 2); LogUtil.e("width:" + width); LogUtil.e("height:" + height); LogUtil.e("getDensity:" + DensityUtil.getDensity(mContext)); LogUtil.e("+++++++++++++++++++++++++++++++++++++++++++++++++:");
因为默认获取的不是真实宽高,是缩放比例的宽高
相关文章推荐
- Android Studio 查找logcat 高亮显示
- Android 设备连接电脑显示offline
- 如何让Android中 dialog显示在屏幕底部
- Android开发报错:AppCompat does not support the current theme features
- Android ListView 图片异步加载和图片内存缓存
- Android 四大组件Broadcast
- android SwipeRefreshLayout google官方下拉刷新控件
- Android使用Activity用作弹出式对话框
- android中Mediaplay的使用
- 深入解析Android中的RecyclerView组件
- Android MediaPlayer使用方法简单介绍
- Android root 原理
- Android插件化原理解析——Hook机制之动态代理
- 模板方法模式(Template Method Pattern
- android中不同类之间的数据通信之接口回调
- Java&Android开发视频教程汇总
- Android通过adb发送input 事件详解
- Android总结03_AsyncTask解析
- 【Android---项目中】复制到剪贴板功能的实现
- android-func-隐藏软键盘