我试图保存图片并在行中 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) { }
答案 0 :(得分:1)
当您从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) { }