zoukankan      html  css  js  c++  java
  • 软工划水日报-安卓端侧部署(4) 4/26

    今天来编写保存图片函数

       //图片储存
        public static String saveBitmap(String name, Bitmap bm, Context mContext) {
            String TargetPath = mContext.getFilesDir() + "/images/";
            Log.d("Save Bitmap", "Save Path="+TargetPath+name);
            if (!fileIsExist(TargetPath)) {
                Log.d("Save Bitmap", "TargetPath isn't exist");
            } else {
                //如果指定文件夹创建成功,那么我们则需要进行图片存储操作
                File saveFile = new File(TargetPath, name);
    
                try {
                    FileOutputStream saveImgOut = new FileOutputStream(saveFile);
                    // compress - 压缩的意思
                    bm.compress(Bitmap.CompressFormat.JPEG, 80, saveImgOut);
                    //存储完成后需要清除相关的进程
                    saveImgOut.flush();
                    saveImgOut.close();
                    Log.d("Save Bitmap", "The picture is save to your phone!");
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            return TargetPath+name;
        }

    这个函数可以保存相应的图像到指定目录以便预测及访问历史

  • 相关阅读:
    orm添加表记录
    创建多表模型
    包的使用
    日志写法
    os模块,是通过和操作系统交互进行操作
    sys python解释器做交互
    软件开发规范
    模块 time模块 datatime模块 random模块
    装饰器
    装饰器进阶
  • 原文地址:https://www.cnblogs.com/Sakuraba/p/14910235.html
Copyright © 2011-2022 走看看