Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging ImageView content causes OutOfMemoryError
    primarykey
    data
    text
    <p>I have a very simple application with one ImageView and a Button. The first Drawable resource loaded by my <strong>ImageView</strong> is specified with the "android:src" tag in the XML Layout, however at runtime i want to <strong>change the picture displayed by it</strong>. To do so i start an Activity for result to pick an image from the sd card (intent sent to MediaStore.Images.Media.EXTERNAL_CONTENT_URI). However when the picture is selected, i try to update the ImageView with the chosen Picture's URI but i get the message "<strong>java.lang.OutOfMemoryError: bitmap size exceeds VM budget</strong>"</p> <p>I'am trying to load pictures taken with the camera (pics size are around 1.1M) of my HTC-Hero but no success, seems to work only with pictures that are less than 500KB.However i need to load pictures taken with the camera. <strong>How can i solve this?</strong> what am I doing wrong. Seem to me that the code is very simple and should work.</p> <pre><code>public void onClick(View v){ Intent selectImageIntent=new Intent(Intent.ACTION_PICK , android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(selectImageIntent,1); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); if(resultCode==Activity.RESULT_OK){ Uri selectedImageUri = data.getData(); Log.i(TAG,"chosen image: "+selectedImageUri.toString()); ImageView imageView = (ImageView) this.findViewById(R.id.ImageView01); imageView.setImageURI(selectedImageUri);//here I get the OutOfMemoryError imageView.invalidate(); }else{ //canceled } } </code></pre> <p>p.s. that is the only thing the App should do, I'm not creating other objects so I will like to point out that I am not using heap space for other stuff besides displaying the image.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload