gpt4 book ai didi

xamarin - 加载图像时出现 OutOfMemoryError

转载 作者:行者123 更新时间:2023-12-02 17:52:15 26 4
gpt4 key购买 nike

我有一个显示图像的简单页面。来源是 URL

   var img = new Image ();
var source = new UriImageSource {
Uri = new Uri (string.Format ("http://xxxx.com/imagem/?{0}", url)),
CachingEnabled = false
};
img .Source = source;

但是当我访问此页面()时,第四次或第五次,我收到此错误

java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:928)
at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
at android.graphics.Bitmap.createBitmap(Bitmap.java:868)
at md5530bd51e982e6e7b340b73e88efe666e.ButtonDrawable.n_draw(Native Method)
at 340b73e88efe666e.ButtonDrawable.draw(ButtonDrawable.java:49)
at android.view.View.draw(View.java:15235)
at android.view.View.getDisplayList(View.java:14141).....

最佳答案

我们遇到了一个非常相似的问题。出现Xamarin has released some guidance on the issue ,但它并不是真正适合 Xamarin Forms。基本上,在设置图像源之前,您需要决定是否应该缩小图像,并手动执行。这可能需要自定义渲染器。

似乎 Xamarin Forms 应该为我们做一些事情,但有时我认为你必须接受坏处和好处。

Here Xamarin 论坛上有关于此问题的讨论。

更新:我刚刚注意到您说这种情况仅在页面加载第四或第五次后才会发生。我们在解决该问题的页面上创建了一个解决方法。基本上,您必须将图像的 Source 设置回 null,并在页面消失时强制进行垃圾回收。像这样:

protected override void OnDisappearing ()
{
base.OnDisappearing ();
img.Source = null;
GC.Collect ();
}

关于xamarin - 加载图像时出现 OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31079620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com