Android 图片选择器

来源:互联网 发布:颈椎牵引器 淘宝 编辑:程序博客网 时间:2024/06/06 04:00

1 事件调用,RESULT_LOAD_IMAGE = 1

Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);         startActivityForResult(i, RESULT_LOAD_IMAGE);
2 选择文件后,返回结果
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]);                          picturePath = cursor.getString(columnIndex);                          Bitmap bitmap = BitmapFactory.decodeFile(picturePath);                        ImageView image = (ImageView) screenShow.findViewById(R.id.hw_update_screen_image_view1);    image.setImageBitmap(bitmap);               screenImage = bitmap;                cursor.close();                      }      }







































0 0
原创粉丝点击