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) { }
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) { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With