Created
July 24, 2012 13:46
-
-
Save jonpryor/3169987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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