Bitmap保存到SD

来源:互联网 发布:淘宝天猫店铺怎么申请 编辑:程序博客网 时间:2024/05/18 16:18
   /**     * 位图保存到SD上     *     * @param bmp 要保存的位图     * @return     */    public static String saveImage(Bitmap bmp) {        Context application = BaseApplication.getContext();        File appDir = new File(application.getExternalFilesDir(null), "temp");        if (!appDir.exists()) {            appDir.mkdir();        }        String fileName = System.currentTimeMillis() + ".jpg";        File file = new File(appDir, fileName);        try {            FileOutputStream fos = new FileOutputStream(file);            bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);            fos.flush();            fos.close();        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }        return file.getAbsolutePath();    }

原创粉丝点击