ХЫтрый ツ
ХЫтрый ツ

Reputation: 53

cannot convert Java.IO.FileOutputStream to System.IO.Stream?

I'm trying to save the picture and in the line bitmapImg.Compress(Bitmap.CompressFormat.Png, 90, fos); displays an error cannot convert Java.IO.FileOutputStream to System.IO.Stream. How to solve it?

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) { }

Upvotes: 3

Views: 4017

Answers (1)

igorc
igorc

Reputation: 2034

The Compress function expects something derived from the .net System.IO.Stream while you passing a class from the java namespace, use the FileStream instead:

    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) { }

Upvotes: 1

Related Questions