Bitmap File path 转换 保存
来源:互联网 发布:龙泉寺的程序员们 编辑:程序博客网 时间:2024/05/08 05:07
public void saveBitmapFile(Bitmap bitmap){ File file=new File(ContactService.getImageURI(Environment.getExternalStorageDirectory()+"/pic/01.jpg");//将要保存图片的路径 try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); }}
/* * 从网络上获取图片,如果图片在本地存在的话就直接拿,如果不存在再去服务器上下载图片 * 这里的path是图片的地址 */ public static Uri getImageURI(String localPath, String path) throws Exception { File file = new File(localPath); // 如果图片存在本地缓存目录,则不去服务器下载 if (file.exists()) { return Uri.fromFile(file);//Uri.fromFile(path)这个方法能得到文件的URI } else { // 从网络上获取图片 URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); conn.setDoInput(true); if (conn.getResponseCode() == 200) { InputStream is = conn.getInputStream(); FileOutputStream fos = new FileOutputStream(file); byte[] buffer = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { fos.write(buffer, 0, len); } is.close(); fos.close(); // 返回一个URI对象 return Uri.fromFile(file); } } return null; }
//BitmapFactory.方法中很多生成bitmap的方法BitmapFactory.decodeFile(filePath, options);
0 0
- Bitmap File path 转换 保存
- bitmap保存为file
- 保存BitMap,File到本地
- 网络图片转为bitmap 转换为文件(File)保存至SD卡中
- Bitmap和File相互转换
- 将Bitmap转换成File
- Android 之 Bitmap 和 File 相互转换
- bitmap与file之间转换使用
- Android File Uri的转换path出错
- URL URI File Path 转换(原创)
- 将Bitmap保存为文件File的方法
- Glide加载图片并保存到本地返回file,bitmap
- Glide加载图片并保存到本地返回file,bitmap
- bitmap保存
- 保存 Bitmap
- Bitmap转换成文件保存到SD卡
- Bitmap与byte、file、Drawable之间的相互转换
- 设置bitmap的宽高,同时将bitmap转换为file对象
- dockerfile 多端口映射 expose
- 车道线检测的相关算法 keywords
- opencl处理的基本流程
- HTML5 sessionStorage和localStorage
- Device eth0 does not seem to be present”解决办法 (常见于克隆系统后出现的网络配置问题)
- Bitmap File path 转换 保存
- GibbsLDA++ Invalid (empty) document!
- net-snmp的安装与配置
- IOS 一些小知识点整理
- skynet浅析
- svn-新建分支-主干合并到分支-分支合并到主干-删除分支
- Android的Paymax接入的微信支付
- cpio文件的解压方法
- java技术大牛修炼记1-大牛真实历程