2
我期待存儲在物理位置是bitmap
,這是我的代碼,沒有Error
沒有Exception
,沒有得到這個形象, 任何需要是有幫助的。無法在指定地點存放,位圖android.xamarin
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.flush()''之前stream.close()'。並請確保您正在檢查設備/模擬器的正確文件夾。 –