我正在尝试保存图片并保存在bitmapImg.Compress(Bitmap.CompressFormat.Png,90,fos)行中;显示错误,无法将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) { }
最佳答案
从Java命名空间传递类时,Compress函数期望从.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) { }
关于c# - 无法将Java.IO.FileOutputStream转换为System.IO.Stream?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44582049/