-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitmapLoader.cs
26 lines (25 loc) · 980 Bytes
/
BitmapLoader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using Android.App;
using Android.Content.Res;
using Android.Graphics;
namespace Segmentus
{
static class BitmapLoader
{
public static Bitmap LoadAndResize(int resID, int width, int height)
{
Resources res = Application.Context.Resources;
BitmapFactory.Options options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
BitmapFactory.DecodeResource(res, resID, options);
int sourceWidth = options.OutWidth;
int sourceHeight = options.OutHeight;
if (sourceWidth > width && sourceHeight > height)
options.InSampleSize = Math.Min(sourceWidth / width, sourceHeight / height);
options.InJustDecodeBounds = false;
Bitmap source = BitmapFactory.DecodeResource(res, resID, options);
Bitmap scaled = Bitmap.CreateScaledBitmap(source, width, height, true);
return scaled;
}
}
}