Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to handle OutOfMemory Exception in xamarin.android

$
0
0

Hey
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.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>