【发布时间】:2017-07-10 19:34:50
【问题描述】:
我希望将 bitmap 存储在物理位置,这是我的代码,没有 Error 没有 Exception,没有得到那个图像,
任何需要都是有帮助的。
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()。请确保您正在检查设备/模拟器的正确文件夹。
标签: android file bitmap xamarin.android