Skip to content

Instantly share code, notes, and snippets.

@monotocho
Forked from jonpryor/gist:3169987
Created July 24, 2012 13:54
Show Gist options
  • Save monotocho/3170016 to your computer and use it in GitHub Desktop.
Save monotocho/3170016 to your computer and use it in GitHub Desktop.
// Quick-and-dirty (and untested!) port of https://gist.github.com/3169945 to C#
Bitmap DecodeFile (string path)
{
var opts = new BitmapFactory.Options () {
InJustDecodeBounds = true,
};
using (var b = BitmapFactory.DecodeFile (path, opts)) {
// Ignore; we're filling `opts`
}
const int RequiredSize = 70;
int w = o.OutWidth;
int h = o.OutHeight;
int scale=1;
while (true) {
if ((w/2 < RequiredSize) || (h/2 < RequiredSize))
break;
h /= 2;
w /= 2;
scale *= 2;
}
var scaleOpts = new BitmapFactory.Options () {
InSampleSize = scale,
};
return BitmapFactory.DecodeFile (path, scaleOpts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment