Forum Xamarin.Android

Best way to change ImageView image?

MaruMaru DEMember ✭✭

Hi everyone!

I have an activity with 6 ImageViews ontop of each other that almost fill out the devices screen. When a button is touched, I need to replace some of the images with others. This action is repeatable, so every time the user touches the button (so changing the image) the available memory is going down till my app gets very slow.
This is what I did to counter that:

using(AndroidGraphics.Bitmap bitmap = await loadBitmap("PathToImageSavedOnDevice"))
{
    using(BitmapDrawable bitmap2 = (BitmapDrawable)imageView1.Drawable)
    {
        imageView1.SetImageBitmap(bitmap);

        if(bitmap2 != null)
        {
            bitmap2.Bitmap.Recycle();
        }
    }
}

loadBitmap just does return await AndroidGraphics.BitmapFactory.DecodeFileAsync(filePath);

I'm loading and changing all my images like above. Is there something I could change or doing entirely wrong here?

Answers

Sign In or Register to comment.