我一般都是这样啦..
try
{
mBitmap=BitmapFactory.decodeFile(resPath);
} catch (OutOfMemoryError e)
{
mBitmap=createFitinBitmap(resPath,SCREEWIDTH,SCREENHEIGHT);
}
public Bitmap createFitinBitmap(String path, int fitinWidth, int fitinHeight)
{
Options opts = new Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, opts);
int sampleSize1 = opts.outWidth / fitinWidth;
int sampleSize2 = opts.outHeight / fitinHeight;
opts.inSampleSize = sampleSize1>sampleSize2? sampleSize1 : sampleSize2;
opts.inJustDecodeBounds = false;
opts.inDither = false;
opts.inPreferredConfig = Bitmap.Config.RGB_565;
return BitmapFactory.decodeFile(path, opts);
}