leonidandand
leonidandand

Reputation: 115

Display big image in ImageView

If I choose the big picture such as it is from Gallery and try display it in ImageView, the ImageView will not display it.

public class ColorViewerActivity extends Activity {

    // SKIP OTHER METHODS

    private static final int SELECT_PHOTO_REQUEST = 100;

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.open_image:
            selectImage();
            break;
        }
        return true;
    }

    private void selectImage() {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, SELECT_PHOTO_REQUEST);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

        switch(requestCode) { 
        case SELECT_PHOTO_REQUEST:
            if (resultCode == RESULT_OK) {
                Uri imageUri = imageReturnedIntent.getData();
                ImageView imageView = (ImageView) findViewById(R.id.imageView);
                imageView.setImageURI(imageUri);
            }
        }
    }
}

Why?? Because the image is too big?

Sorry for my English.

Thanks

Upvotes: 0

Views: 932

Answers (1)

stinepike
stinepike

Reputation: 54672

If you use huge image which exceeds your memory it will Throw

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

To know how to display bitmaps efficiently check this link

Upvotes: 1

Related Questions