2017-06-16 79 views
0

我試圖保存圖片並在行bitmapImg.Compress(Bitmap.CompressFormat.Png,90,fos);顯示錯誤無法將Java.IO.FileOutputStream轉換爲System.IO.Stream。如何解決它?無法將Java.IO.FileOutputStream轉換爲System.IO.Stream?

File file = new File(Android.OS.Environment.DirectoryPictures + File.Separator + "newProdict.png"); 
      FileOutputStream fos = null; 
      try 
      { 
       fos = new FileOutputStream(file); 
       if (fos != null) 
       { 
        bitmapImg.Compress(Bitmap.CompressFormat.Png, 90, fos); 
        fos.Close(); 
       } 
      } 
      catch (Exception ex) { } 
+0

位圖是我的圖像m試圖保存到智能手機的畫廊。 C# –

+1

我相信你應該用FileStream代替FileOutputStream –

+0

編輯我的回答路徑 –

回答

1

壓縮功能期待,而你從Java命名空間傳遞一個類從.NET System.IO.Stream派生出來的,使用FileStream來代替:

try 
    { 

    string path = Path.Combine(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).AbsolutePath, "newProdict.png"); 
    var fs = new FileStream(path, FileMode.Open); 
     if (fs != null) 
     { 
      bitmapImg.Compress(Bitmap.CompressFormat.Png, 90, fs); 
      fos.Close(); 
     } 
    } 
    catch (Exception ex) { } 
+0

找不到路徑的一部分「/Pictures/newProdict.png」 –

+0

太棒了。如果你可以幫助解決這個問題的答案?[鏈接](https://stackoverflow.com/questions/44584067/how-to-get-the-path-to-the-internal-memory-of-the-smartphone-和-dimim文件夾) –

+0

@ХЫтрыйз嘗試'FileMode.OpenOrCreate' – Pierre

相關問題