【问题标题】:How can I store captured image from camera with bmp filename extension如何使用 bmp 文件扩展名存储从相机捕获的图像
【发布时间】:2017-07-11 02:47:59
【问题描述】:

当我在裁剪后存储从相机捕获的图像时,裁剪后的 jpg 图像文件是

存储在我指定的文件夹中。

我想存储带有 bmp 文件扩展名的“那个”裁剪图像文件。

【问题讨论】:

  • 如果一个帖子解决了你的问题,请标记为答案,这是礼貌的方式。

标签: android image


【解决方案1】:

我建议的步骤是:

  1. 裁剪后的 jpg 使用此代码将其转换为位图

    Bitmap bMap = BitmapFactory.decodeFile(imgPath);
    
  2. 使用 bmp 扩展保存 bMap,您可以通过 HERE 遵循建议功能

  3. 删除裁剪的 jpg 文件以释放内存

    File dir = getFilesDir();
    
    File file = new File(dir, "filename");
    
    if (file.exists()) {
    
     boolean deleted = file.delete();
    
    }
    

【讨论】:

    【解决方案2】:

    试试下面的代码 -

                FileOutputStream out = null;
                try {
                    out = new FileOutputStream(AbsoluteFilePath);
                    bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
                    // PNG is a lossless format, the compression factor (100) is ignored
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (out != null) {
                            out.close();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
    

    来源:Save bitmap to location

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      相关资源
      最近更新 更多