Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android,将图像(在ImageView中)保存到移动设备_Android_Imageview_Save Image - Fatal编程技术网

Android,将图像(在ImageView中)保存到移动设备

Android,将图像(在ImageView中)保存到移动设备,android,imageview,save-image,Android,Imageview,Save Image,我想寻求一些帮助。目前,我面临如何保存imageview中显示的图像的问题 因此,我在imageview中有一张图片,在底部有一个保存按钮。那么,我该如何将此图像保存到我的移动设备上呢 澄清一些疑问 我在imageview中有一个jpg文件。所以我想通过点击一个按钮来保存这个图像文件,我把它放在imageview的正下方。因此,现在我面临一个无法保存文件的问题 谢谢您正在imageview中设置的图像是什么?任何可绘制的或任何来自服务器的图像?我正在应用程序本身中设置图像。我尝试了你的代码,但遇

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

因此,我在imageview中有一张图片,在底部有一个保存按钮。那么,我该如何将此图像保存到我的移动设备上呢

澄清一些疑问

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


谢谢

您正在imageview中设置的图像是什么?任何可绘制的或任何来自服务器的图像?我正在应用程序本身中设置图像。我尝试了你的代码,但遇到异常。这是否需要任何外部SD卡?或者,它可以存储在手机的内置空间中。你没有稍微更改代码,但还行,所以你现在只做一件事:文件根=新文件(Environment.getExternalStorageDirectory()+File.separator+“folder\u name”+File.separator);现在,由于您的手机中没有folder\u name folder,因此请将您的行添加到这个文件root=new File(Environment.getExternalStorageDirectory();因为您现在跳过的行将定义一个在Environment时保存照片的位置。getExternalStorageDirectory()提供了手机中默认位置的路径谢谢,我将尝试一下:)
   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) {
   }