无法在android.xamarin中的指定位置存储位图

时间:2017-02-21 09:06:09

标签: android file bitmap xamarin.android

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

1 个答案:

答案 0 :(得分:0)

检查清单enter image description here

中的写入权限