2012-05-05 42 views
0

我没有解决这个错误成功:位图和相机

java.lang.OutOfMemoryError: bitmap size exceeds VM budget.

我的代码是:

BitmapFactory.Options op = new BitmapFactory.Options(); 
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),op); 
ImageView _image = (ImageView)view.findViewById(R.id.imageCarte); 

int width = myBitmap.getWidth(); 
int height = myBitmap.getHeight(); 
int halfWidth = width/2; 
int halfHeight = height/2; 
Bitmap bmHalf = Bitmap.createScaledBitmap(myBitmap, halfWidth, halfHeight, false); 
_image.setImageBitmap(bmHalf); 
+0

这个问题是转贴:http://stackoverflow.com/questions/10460588/java-lang-的OutOfMemoryError#comment13509696_10460588。 –

回答

0

您可以在BitmapFactory.Options实例指定inSampleSize

If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory.

例如:

BitmapFactory.Options op = new BitmapFactory.Options(); 
op.inSampleSize = 2 
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),op); 
ImageView _image = (ImageView)view.findViewById(R.id.imageCarte); 
_image.setImageBitmap(myBitmap);