读书人

从gally取舍出一个图片

发布时间: 2012-09-07 10:38:15 作者: rapoo

从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 很好的 学习学习 谢谢啦

读书人网 >移动开发

热点推荐