2

I'm facing memory problem with image loading in xamarin forms list view, now i need to implement bitmap image in forms but i cant do that in xamarin forms i can't find any namespace including bit map in xamarin forms i have a normal data binding code which also binds image too

 public async void GetResult()
    //public  void GetResult()
    {
        try
        {
            IsBusy = true;
            var client = new HttpClient();
            var json = await client.GetStringAsync(string.Format(Url));
            var items = JsonConvert.DeserializeObject<ObservableCollection<cm_main_category>>(json.ToString());
            foreach (var item in items)
            {
                 item.image_url = "http://somelink.net" + item.image_url.Substring(1, item.image_url.Length - 1);
               // item.image_url = "http://127.0.0.1" + item.image_url.Substring(1, item.image_url.Length - 1);
                ListItems.Add(item);
            }
            IsBusy = false;
        }

now i nee to implement bit map to this code what should be the approach ?

3 Answers 3

1

If you want to save memory, you could try to use FFImageLoading CachedImage which is Image API compatible replacement with advanced memory caching and downsampling capabilities. Just replace Image with CachedImage and set one of its downsampling properties.

https://github.com/molinch/FFImageLoading

Sign up to request clarification or add additional context in comments.

Comments

0

Obviously you want to bind the image by URI. That's pretty easy in Xamarin.Forms.

You simply need to bind the ImageSourceProperty of an ImageCell to the property that knows the URI. A great example for both XAML binding and C# binding can be found here: https://www.syntaxismyui.com/xamarin-forms-listview-imagecell-recipe/

EDIT: Copied from the comments: The solution is to set the image source to null and trigger the garbage collection as described here: OutOfMemoryError when loading an image

8 Comments

i can do that , and also i can populate listview with images also but the problem is i can't add more data to it because of memory error and i need the image to bitmap how can i implement bitmap image instead of normal image
What is the memory error you are facing? Do you receive an OutOfMemoryException? Then read this developer.xamarin.com/recipes/android/resources/general/…
yes i am getting the OutOfMemoryException how can i implement it on forms that link is about native i need forms thank for your replay
I only know about memory issues reagarding images on android. Other users have already faced this problem. I think their solutions can help you 1. stackoverflow.com/questions/25807196/… 2. stackoverflow.com/questions/31079620/…
Also try to set Java heap size to eg. 1GB in Android Project options. I think it will fix your memory issues.
|
0
 protected override void OnDisappearing()
    {
        BindingContext = null;
        Content = null;
        base.OnDisappearing();
        GC.Collect();
    }

on some app this will help if your app is dealing with thousands of data with image better adding bitmap

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.