无法在android.xamarin中的指定位置存储位图
我想在物理位置存储无法在android.xamarin中的指定位置存储位图,android,file,bitmap,xamarin.android,Android,File,Bitmap,Xamarin.android,我想在物理位置存储位图,这是我的代码,无错误无异常,无法获取该图像, 任何需要都是有帮助的 public void Downloads() { Bitmap bm = GetImageBitmapFromUrl("https://bsujournalismworkshops.files.wordpress.com/2016/10/jpg.png"); try { var sdCardPath = Android.OS.En
位图
,这是我的代码,无错误
无异常
,无法获取该图像,
任何需要都是有帮助的
public void Downloads()
{
Bitmap bm = GetImageBitmapFromUrl("https://bsujournalismworkshops.files.wordpress.com/2016/10/jpg.png");
try
{
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var filePath = System.IO.Path.Combine(sdCardPath,"jpg.png");
var stream = new FileStream(filePath, FileMode.Create);
bm.Compress(Bitmap.CompressFormat.Png, 100, stream);
stream.Close();
}
catch (Exception e)
{
string Exe=e.ToString();
}
}
public Bitmap GetImageBitmapFromUrl(string url)
{
Bitmap imageBitmap = null;
try
{
using (var webClient = new WebClient())
{
var imageBytes = webClient.DownloadData(url);
if (imageBytes != null && imageBytes.Length > 0)
{
imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
}
}
}
catch (Exception)
{
return null;
}
return imageBitmap;
}
检查清单中的写入权限请尝试在
stream.close()之前添加stream.flush()
。请确保您正在检查设备/仿真器的正确文件夹。您必须卸载并再次调试它。它对我有用。