在ImageView中显示大图像

时间:2013-05-04 21:45:02

标签: android android-imageview

如果我从图库中选择it is等大图片并尝试在ImageView中显示,则ImageView将不会显示它。

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);
            }
        }
    }
}

为什么?因为图像太大了?

抱歉我的英文。

由于

1 个答案:

答案 0 :(得分:1)

如果您使用超出记忆的巨大图像,则会抛出

  

java.lang.OutofMemoryError:位图大小超过VM预算。

要知道如何有效地显示位图,请检查this link