So, i was working on a project that loads an image from the gallery and set as background. It is working perfectly fine but crashes when i try to load a large image, i.e. 5 MP (2592х1944), 8mpx (3264x2448), 12 MP, 4000x3000 , here is my code:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK && requestCode == 0) { Uri photo = data.getData(); ContentResolver resolver = getContentResolver(); resolver.notifyChange(photo, null); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(resolver, photo); FrameLayout bg = (FrameLayout) findViewById(R.id.frame); Drawable drawable = new BitmapDrawable(getResources(), bitmap); bg.setBackgroundDrawable(drawable); // Do something useful with your bitmap } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } here is the logcat 08-13 04:44:01.414: E/AndroidRuntime(11062): FATAL EXCEPTION: main 08-13 04:44:01.414: E/AndroidRuntime(11062): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 08-13 04:44:01.414: E/AndroidRuntime(11062): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 08-13 04:44:01.414: E/AndroidRuntime(11062): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459) 08-13 04:44:01.414: E/AndroidRuntime(11062): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515) 08-13 04:44:01.414: E/AndroidRuntime(11062): at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:503) Any help through code snippet/ tutorial would be more fruitful. Thanks! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en