我希望将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;
}