【问题标题】:android give name to bitmap and save itandroid给位图命名并保存
【发布时间】:2012-02-10 09:58:26
【问题描述】:

我有一张想要保存到 SD 卡的位图。我有两个问题:

  1. 为保存的文件设置名称
  2. 保存文件

我环顾 Stack Overflow 并找不到任何有效的方法,这两个问题(主要是保存部分,集合名称部分让我很困惑)

有没有简单直接的解决方案?

谢谢!

【问题讨论】:

    标签: android string bitmap save


    【解决方案1】:
    Bitmap yourBitmap; // you have to get your bitmap into this variable
    String filePath = "/mnt/sdcard/"; // some times it may be only /sdcard not /mnt/sdcard
    filePath += "newFileName.jpg";
    
            try {
                yourBitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File(filePath)));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    

    您必须在清单文件中使用以下权限。

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    【讨论】:

    • 之前或在之后
    • YESSSSSSSSSSSSSSSSSSSSSSS 成功了!!!!是 /sd_card 而不是 /mnt/sd_card 非常感谢!!!!!!!!!
    【解决方案2】:

    试试这个:

    FileOutputStream out = new FileOutputStream(new File("/mnt/sdcard/pic.jpg"));
    yourBitmap.compress(Bitmap.CompressFormat.JPG, 80, out);
    out.close();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 2012-01-07
      • 2014-05-11
      • 2015-04-23
      • 2014-07-28
      • 1970-01-01
      相关资源
      最近更新 更多