0
即时通讯尝试访问并从我的手机厨房选择一个图像到我的应用程序imageView,使用android。到目前为止,我设法进入厨房,选择我想使用的图像,唯一的问题是,一旦选择了我想要的图像,我不能将它放到imageview上。这个问题似乎是,我的主类中有一个imageview类独立。我检查并找不到解决方案。从手机厨房Imageview
继承人为mediagalley类的代码
公共类MediaGallery延伸活动{ 公共静态最终诠释SELECT_IMAGE = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == SELECT_IMAGE) {
Uri selectedImage = data.getData();
String path = getPath(selectedImage);
Bitmap bitmapImage = BitmapFactory.decodeFile(path);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bitmapImage);
}
}
public String getPath(Uri uri) {
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, filePathColumn, null,null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
return cursor.getString(columnIndex);
}
}
和主类代码
case R.id.gallery_button:
MediaGallery activ1 = new MediaGallery();
Intent gallery = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, 1);
activ1.onActivityResult(1, 1, gallery);
break;
ü给给金正日很感激