2013-05-04 138 views
0

如果我从Gallery中选择大图片(如it is)并尝试在ImageView中显示它,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

看来的是因为这个原因。 WebView可以显示大型项目,但有时会抛出内存异常。 – vorrtex 2013-05-05 11:14:22

回答

1

如果使用超过你的记忆庞大的图像会抛出

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

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

+0

此图片是只有〜2 Mb – leonidandand 2013-05-05 11:06:08