Possible Duplicate:
OutOfMemoryError: bitmap size exceeds VM budget :- Android
Im in the process of writing a program which uses images from the gallery and then displays them in an activity (one image pr. activity). However I've been bumping into this error over and over again for three days straight without doing any progress of eliminating it:
07-25 11:43:36.197: ERROR/AndroidRuntime(346): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
My code flow is as follows:
When the user presses a button an intent is fired leading to the gallery:
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, 0);
Once the user has selected an image the image is presented in an imageview:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:background="#ffffffff"
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:maxWidth="250dip"
android:maxHeight="250dip"
android:adjustViewBounds="true"/>
</LinearLayout>
In the onActivityResult method i have:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
switch(requestCode) {
case 0: // Gallery
String realPath = getRealPathFromURI(data.getData());
File imgFile = new File(realPath);
Bitmap myBitmap;
try {
myBitmap = decodeFile(imgFile);
Bitmap rotatedBitmap = resolveOrientation(myBitmap);
img.setImageBitmap(rotatedBitmap);
OPTIONS_TYPE = 1;
} catch (IOException e) { e.printStackTrace(); }
insertImageInDB(realPath);
break;
case 1: // Camera
The decodeFile method is from here and the resolveOrientation method just wraps the bitmap into a matrix and turns it 90 degrees clockwise.
I really hope someone can help me resolve this matter.