Android不加载获取网络、本地图片的尺寸
来源:互联网 发布:淘宝小号怎样申请 编辑:程序博客网 时间:2024/06/08 13:24
一、根据网络数据流来获取大小
class GetImageSizeTask extends AsyncTask<Void, Void, Boolean> { String TAG = this.getClass().getName(); String urlStr = "http://www.3dmgame.com/uploads/allimg/160902/328_160902163518_1.jpg"; int width, height; @Override protected Boolean doInBackground(Void... voids) { boolean result = false; try { URL mUrl = new URL(urlStr); HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection(); InputStream is = connection.getInputStream(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(is, null, options); width = options.outWidth; height = options.outHeight; result = true; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } @Override protected void onPostExecute(Boolean aBoolean) { if(aBoolean) { Log.i(TAG, "width: " + width + " height: " + height); } else { Log.i(TAG, "获取失败"); } } }
二、利用Glide来获取图片大小
String url = "http://www.3dmgame.com/uploads/allimg/160902/328_160902163518_1.jpg"; Glide.with(this).asBitmap().load(url).into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { Log.i("TAG", "width: " + resource.getWidth() + " height: " + resource.getHeight()); } });
三、获取本地图片尺寸
String src = "/mnt/sdcard/names.jpg"; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; //bitmap.options类为bitmap的裁剪类,通过他可以实现bitmap的裁剪;如果不设置裁剪后的宽高和裁剪比例,返回的bitmap对象将为空,但是这个对象存储了原bitmap的宽高信息,bitmap对象为空不会引发OOM。 Bitmap bitmap = BitmapFactory.decodeFile(src, options); int width = options.outWidth; int height = options.outHeight; Log.i("TAG", "width: " + width + " height: " + height);
阅读全文
0 0
- Android不加载获取网络、本地图片的尺寸
- 获取网络图片的尺寸
- iOS 异步加载网络图片,获取图片真实尺寸
- 获取网络图片的尺寸大小
- IOS获取网络图片的尺寸
- ios获取网络图片的尺寸
- iOS 获取网络图片的尺寸
- Android:图片不加载到内存获取图片的大小
- Android中加载网络图片到本地
- Android imageloader加载网络,本地图片方式
- Android 本地加载网页&显示网络图片
- Android imageloader加载网络,本地图片方式
- java获取图片的大小和尺寸(本地& 服务器)
- js在前端获取在本地上传图片的尺寸
- 本地保存gif图片,实现第二次不网络加载
- android 获取不带后缀的网络图片
- 网络加载图片并实现本地缓存与获取
- Weex Android加载本地图片及网络图片
- Java.util.Math类的API记录
- 获取url参数
- SpringBoot 中文手册 --Part IV --32 消息
- 20171031|课堂作业02 方法参数相关博文
- java.lang.NoSuchMethodError 错误的原因及解决办法
- Android不加载获取网络、本地图片的尺寸
- MTK 充电逻辑总结
- java判断string变量是否是数字的六种方法小结
- 关于大数据,需要你读懂的10个小故事
- android Bluetooth 开发1之布局和权限
- 有人问我:程序员要供祖师爷的话该供谁?
- BZOJ1962: 模型王子(猜数问题DP)
- 选择CAD快速看图软件操作
- Unity 在IOS上播放视频不能跳过