Android 中读取图片方式分享
来源:互联网 发布:微信里淘宝链接 编辑:程序博客网 时间:2024/05/18 12:41
Android 中读取图片方式分享
一:读取res中的图片//读取本地res中的图片public static Bitmap readBitmap(int resid){<span style="white-space:pre"></span>BitmapFactory.Options opt = new BitmapFactory.Options();<span style="white-space:pre"></span>opt.inPreferredConfig = Bitmap.Config.RGB_565;<span style="white-space:pre"></span>opt.inPurgeable = true;<span style="white-space:pre"></span>opt.inInputShareable = true;<span style="white-space:pre"></span>//获取资源图片<span style="white-space:pre"></span>InputStream input = getResources().openRawResource(resid);<span style="white-space:pre"></span>return BitmapFactory.decodeStream(input,null,opt);}<span style="white-space:pre"></span>//确定不再需要该bitmap对象的时候可以将其回收掉<span style="white-space:pre"></span>public static void recycle(Bitmap bitmap){<span style="white-space:pre"></span>if(bitmap!=null && !bitmap.isRecycle()){<span style="white-space:pre"></span>bitmap.recycle();<span style="white-space:pre"></span>System.gc();//提醒系统及时回收 }}二:放在assets中的图片(只读)<span style="white-space:pre"></span>InputStream is = context.getResources().getAssets().open("icon.png");<span style="white-space:pre"></span>Bitmap bitmap = BitmapFactory.decodeStream(is);<span style="white-space:pre"></span>三:读取sd卡中的图片<span style="white-space:pre"></span>Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/icon.png");<span style="white-space:pre"></span>四:读取网络图片<span style="white-space:pre"></span>public static Bitmap loadImageFromUrl(String urlStr){<span style="white-space:pre"></span>URL url;<span style="white-space:pre"></span>InputStream i = null;<span style="white-space:pre"></span>try{<span style="white-space:pre"></span>m = new URL(urlStr);<span style="white-space:pre"></span>i = m.getContent();<span style="white-space:pre"></span>}catch(Exception e){<span style="white-space:pre"></span>e.printStaceTrace();<span style="white-space:pre"></span>}<span style="white-space:pre"></span>return BitmapFactory.decodeStream(i);}
0 0
- Android 中读取图片方式分享
- Android 中读取图片方式分享
- Android读取图片资源的4中方式
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- android 分享纯图片到QQ空间实现方式
- android 直接从配置文件中读取图片
- [Android]反射读取drawable中图片
- Android从Assets中读取图片
- Android 如何以流的方式读取图片文件
- android 通过uri等方式读取图片资源
- Android 4.4前后版本读取图库图片方式的变化
- Android 以流的方式读取服务器图片文件
- Android调用原声分享相关的知识以及保存图片读取图片
- hibernate批量修改,批量删除
- 关于null的说明以及和0的区别
- vsflex8.ocx已加载,但对DLLREGISTERSERVER的调用失败
- 快速开发框架XUtils
- 各种排序算法的分析及java实现
- Android 中读取图片方式分享
- ubuntu的grub引导菜单一闪而过,无法操作
- failed tcp accept emfile; erlang ;ejabberd;tsung
- C#的百度地图开发(三)依据坐标获取位置、商圈及周边信息
- 初学perl
- FactoryBean与BeanFactory
- 单例模式
- SurfaceFlinger研究(一)
- Leetcode Distinct Subsequences 动态规划法活用总结