首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

从gally取舍出一个图片

2012-09-07 
从gally选择出一个图片Intent i new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.M

从gally选择出一个图片

Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); startActivityForResult(i, ACTIVITY_SELECT_IMAGE);??

?

或者

?

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);?
intent.setType("image/*");?
startActivityForResult(intent, IMAGE_PICK);?

然后主要是下面的实现

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { ?
? ? super.onActivityResult(requestCode, resultCode, imageReturnedIntent); ?
?
? ? switch(requestCode) { ?
? ? case REQ_CODE_PICK_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(filePathColumn[0]);?
? ? ? ? ? ? String filePath = cursor.getString(columnIndex);?
? ? ? ? ? ? cursor.close();?
?
?
? ? ? ? ? ? Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);?
? ? ? ? }?
? ? }?
}?

1 楼 蓝月儿 2011-04-13   很好的 学习学习 谢谢啦

热点排行