0

我想寻求一些帮助。目前我面临如何保存图像视图中显示的图像的问题。

所以我在图像视图中有一张图片,底部有一个保存按钮。那么我如何将这张图片实际保存到我的移动设备上。

澄清一些疑问。

我在 imageview 中有一个 jpg 文件。所以我想通过点击一个按钮来保存那个图像文件,我把它放在图像视图的正下方。所以现在我面临一个问题,我无法保存文件。

谢谢你

4

1 回答 1

1
   1.  For getting image from ImageView

      imageview.buildDrawingCache();
      Bitmap bm=imageview.getDrawingCache();

   2.  For saving that in a file

    OutputStream fOut = null;
    Uri outputFileUri;
     try {
    File root = new File(Environment.getExternalStorageDirectory()
      + File.separator + "folder_name" + File.separator);
    root.mkdirs();
   File sdImageMainDirectory = new File(root, "myPicName.jpg");
    outputFileUri = Uri.fromFile(sdImageMainDirectory);
    fOut = new FileOutputStream(sdImageMainDirectory);
   } catch (Exception e) {
    Toast.makeText(this, "Error occured. Please try again later.",
      Toast.LENGTH_SHORT).show();
   }

   try {
    bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    fOut.flush();
    fOut.close();
   } catch (Exception e) {
   }
于 2014-08-26T09:11:23.157 回答