zoukankan      html  css  js  c++  java
  • Android--将图片存放到我们本地

    代码里面有详细的解释,我就不多说了

     1 //处理并保存图像
     2     private File dealPhoto(Bitmap photo){
     3         FileOutputStream fileOutputStream = null;
     4         //图片的名称,已时间命名
     5         SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); //时间格式
     6         Date date = new Date(System.currentTimeMillis());   //当前时间
     7         String photoName = format.format(date);      //格式化名称
     8         //图片存放地址
     9         File saveDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); //保存到系统图库中
    10         File file = new File(saveDir,photoName+".jpg");  //在这个路径下生成这么一个文件生成这么一个文件
    11         try {
    12             fileOutputStream = new FileOutputStream(file);  //将本地图片读成流
    13             photo.compress(Bitmap.CompressFormat.JPEG,100,fileOutputStream);   //保存图片到本地,100是压缩比率,表示100%压缩
    14 
    15         } catch (FileNotFoundException e) {
    16             e.printStackTrace();
    17         }finally {
    18             if (photo != null && photo.isRecycled()){
    19                 photo.recycle();   //释放内存
    20             }
    21             try {
    22                 if (fileOutputStream != null) {
    23                     fileOutputStream.close();
    24                 }
    25             } catch (IOException e) {
    26                 e.printStackTrace();
    27             }
    28         }
    29         return file;
    30     }
  • 相关阅读:
    EF 学习代码
    VS10 调试 新功能
    高级编程 实验代码
    事务 代码
    ADO.NET的新功能:MARS(Multiple Active Result Set) 及 异步执行命令
    Log4Net
    获得CheckBoxList最后一个被操作的项
    在存储过程中用事务
    ASP.NET服务端添加客户端事件
    GridView遍历各行的控件和控件事件
  • 原文地址:https://www.cnblogs.com/819158327fan/p/4906404.html
Copyright © 2011-2022 走看看