Exception picking a image from gallery (SD Card) for use on my app... ¿why?
i am picking images on my app with android, and i dont know why, sometimes i got an exception, i think it's allways i select a image with more than 400 or 500 kb's but i am not sure. Why? because when i select small images of 100 kb i dont get the exception, and when i get images with 500kb or 1.5 mb yes, it crash
i dont know wich exception is because i have to test this functionality with my phone, i can't test with the emulator because i dont know how to put images on the emulator.
this is my code:
changeImageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 1:
{
setResult(1);
finish();
}
case ACTIVITY_SELECT_IMAGE:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(fileP开发者_开发知识库athColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
selectedPhoto = BitmapFactory.decodeFile(filePath);
//profileImage.setImageBitmap(selectedPhoto);
profileImage.setImageBitmap(Bitmap.createScaledBitmap(selectedPhoto, 80, 80, false));
}
}
}
profileImage is a ImageView of my layout. and i use scaled butmap to resice the image to 80x80
please give me some help with this exception, i need to solve it
thanks
I just dumped your code into my phone and it works just fine. I also tried 5.5 megabyte images without a problem.
I guess what I would recommend is setting up an SD card on your emulator. There are plenty of tutorials on how to do this on the internet. Once you set up the SD card on the emulator, you will be able to get the exception in LogCat and determine where you are going wrong.
精彩评论