Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) { }
like image 1000
ХЫтрый ツ Avatar asked Sep 03 '26 03:09

ХЫтрый ツ


1 Answers

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) { }
like image 94
igorc Avatar answered Sep 05 '26 18:09

igorc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!