【发布时间】:2018-02-05 03:23:46
【问题描述】:
我正在使用下面的代码下载图片:
var webClient = new WebClient();
webClient.DownloadDataCompleted += (s, e) =>
{
var bytes = e.Result; // get the downloaded data
//string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string documentsPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/" + Android.OS.Environment.DirectoryPictures + "/";
string localFilename = img.Uri.LocalPath.Split('/').Last();
string localPath = System.IO.Path.Combine(documentsPath, localFilename);
File.WriteAllBytes(localPath, bytes); // writes to local storage
Bitmap bmp = BitmapFactory.DecodeFile(localPath);
using (var os = new FileStream(localPath, FileMode.Truncate))
{
bmp.Compress(Bitmap.CompressFormat.Jpeg, 95, os);
}
};
webClient.DownloadDataAsync(img.Uri);
问题是图像显示在文件上而不是画廊上。我在安卓上运行。
我该如何解决这个问题?
【问题讨论】:
标签: android xamarin download xamarin.forms gallery