android调用系统图库的问题
看了下关于调用系统图库的问题,有些疑问,@OverrideprotectedvoidonActivityResult(intrequestCode,intresultCo...
看了下关于调用系统图库的问题,有些疑问,
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.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 picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imgView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
首先,String[] filePathColumn = { MediaStore.Images.Media.DATA };
请问,int columnIndex = cursor.getColumnIndex(filePathColumn[0]);是取得列名为“DATA”的一列的信息吧。那么我想问,Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);为什么又要在query里面第二个参数写filePathColumn呢? 展开
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.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 picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imgView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
首先,String[] filePathColumn = { MediaStore.Images.Media.DATA };
请问,int columnIndex = cursor.getColumnIndex(filePathColumn[0]);是取得列名为“DATA”的一列的信息吧。那么我想问,Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);为什么又要在query里面第二个参数写filePathColumn呢? 展开
推荐于2018-11-21
展开全部
调用系统图库:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"选择图片"), 2);
获取图片的内容:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Drawable d =null;
if (requestCode == 2) {
if (Activity.RESULT_OK == resultCode) {
Uri uri1 = data.getData();
Cursor cursor = this.getContentResolver().query(uri1, new String[]{"_data"},null, null, null);
if(cursor.moveToFirst()){
String otherfile = cursor.getString(0);
d=Drawable.createFromPath(otherfile );
}
}
}
}
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"选择图片"), 2);
获取图片的内容:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Drawable d =null;
if (requestCode == 2) {
if (Activity.RESULT_OK == resultCode) {
Uri uri1 = data.getData();
Cursor cursor = this.getContentResolver().query(uri1, new String[]{"_data"},null, null, null);
if(cursor.moveToFirst()){
String otherfile = cursor.getString(0);
d=Drawable.createFromPath(otherfile );
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询