title: How to save an image to Internal Storage and then show it on another activity?
body: <p>I am working in Xamarin.Android. I have two activities on which I need to show the same image. On the first screen, I download it from a web URL and show it but I don't want to do the same on second screen. I want to save it to Internal Storage when it gets downloaded on the first screen and then simply retrieve it from there to show on second activity. How can I do that?</p>
  
  <p>Here is my code that I am using on first activity:</p>
  
  <pre><code>protected override void OnCreate (Bundle bundle)
  {
      base.OnCreate (bundle);
  
      this.SetContentView (Resource.Layout.Main);
  
      String uriString = this.GetUriString();
      WebClient web = new WebClient ();
      web.DownloadDataCompleted += new DownloadDataCompletedEventHandler(web_DownloadDataCompleted);
      web.DownloadDataAsync (new Uri(uriString));
  }
  
  void web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
  {
      if (e.Error != null)
      {
          RunOnUiThread(() =&gt;
              Toast.MakeText(this, e.Error.Message, ToastLength.Short).Show());
      }
      else
      {
          Bitmap bm = BitmapFactory.DecodeByteArray(e.Result, 0, e.Result.Length);
  
          // THIS IS WHERE I NEED TO SAVE THE IMAGE IN INTERNAL STORAGE //
  
          RunOnUiThread(() =&gt;
              {
                  ProgressBar pb = this.FindViewById&lt;ProgressBar&gt; (Resource.Id.custLogoProgressBar);
                  pb.Visibility = ViewStates.Gone;
  
                  ImageView imgCustLogo = FindViewById&lt;ImageView&gt;(Resource.Id.imgCustLogo);
                  imgCustLogo.SetImageBitmap(bm);
              });
      }
  }
  </code></pre>
  
  <p>Now for saving the image, here is what I did inspired by <a href="https://stackoverflow.com/questions/17674634/saving-images-to-internal-memory-in-android" title="this">this</a>:</p>
  
  <pre><code>        Bitmap bm = BitmapFactory.DecodeByteArray(e.Result, 0, e.Result.Length);
  
          ContextWrapper cw = new ContextWrapper(this.ApplicationContext);
          File directory = cw.GetDir("imgDir", FileCreationMode.Private);
          File myPath = new File(directory, "test.png");
  
          FileOutputStream fos = null;
          try 
          {
              fos = new FileOutputStream(myPath);
              bm.Compress(Bitmap.CompressFormat.Png, 100, fos);
              fos.Close();
          }
          catch (Exception ex) 
          {
              System.Console.Write(ex.Message);
          }
  </code></pre>
  
  <p>However, the code does not compile and I get an exception where I call <code>bm.Compress()</code>. It says:</p>
  
  <pre><code>Error CS1503: Argument 3: cannot convert from 'Java.IO.FileOutputStream' to 'System.IO.Stream'
  </code></pre>