【问题标题】:Not able to store bitmap in specified location in android.xamarin无法将位图存储在 android.xamarin 的指定位置
【发布时间】: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


【解决方案1】:

检查manifest中的写权限

【讨论】:

  • 你必须卸载并再次调试它对我有用。
猜你喜欢
  • 1970-01-01
  • 2011-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多