How to handle OutOfMemory Exception in

Amit.7951Amit.7951 USMember ✭✭
edited December 2017 in Xamarin.Android

I am new to Android

I am resizing a Bitmap, for this when I create a blank Bitmap with a high resolution, it throws OutOfMemory Exception. How to deal with this.

public Bitmap getResizedBitmap(Bitmap originalBitmap, int maxWidth, int maxHeight)
Bitmap res = Bitmap.CreateBitmap(4000, 4000, Bitmap.Config.Argb8888);
Canvas can = new Canvas(res);
Paint paint = new Paint();
paint.FilterBitmap = false;
can.DrawBitmap(originalBitmap, new Matrix(), paint);

    return res;

When I choose for low resolution Bitmap then it works fine and the issue is with the high resolution images.

I also noticed that when I give different resolution in compared to originalBitmap then the output of the res is cropped, and not resized.

Any help would be appreciated.



Sign In or Register to comment.