android 图片加载
16lz
2021-01-26
/** * 因为考虑到网络下载的速度,我想到了保存图片到sd卡,先判断图片是否保存到sd卡中 * 如果保存到卡里就调用sdcardbitmap,否则调用bitmap从网络读取 * * @param path * @return */public boolean ifmap(String path) {File file = new File("/sdcard/myfood/" + path + ".jpg");if (file.exists()) {return true;}return false;}/** * 从网络读取 * * @param url * @return */public Bitmap bitmap(String url) {StreamTool StreamTool1 = new StreamTool();try {InputStream isInputStream = StreamTool1.getis(context.localhost()+ url);Bitmap bitmap = BitmapFactory.decodeStream(isInputStream);isInputStream.close();return bitmap;} catch (Exception e) {e.printStackTrace();}return null;}/*** * 从sd卡读取 * * @param filepath * @return */public Bitmap sdcardbitmap(String filepath) {try {File file = new File(filepath);if (file.exists()) {Bitmap bitmap = BitmapFactory.decodeFile(filepath);return bitmap;}} catch (Exception e) {e.printStackTrace();}return null;}
更多相关文章
- Android(安卓)读取元素的数据
- Android平台上四种保存数据的方法
- Android存储和加载本地文件(内部存储设备)
- dom读取xml文档---android
- Android(安卓)opengl ES实现后台绘图并保存为bitmap
- Android(安卓)Q私有目录与公共目录文件的交互(读取,复制,保存等)——
- android 拍照的照片方向问题,读取图片EXIF信息
- Android读取应用列表权限漏洞
- Android群发短信草稿保存与发送机制