在我的布局中,我使用一个按钮从图库中选择图像,我想点击相关布局当前活动的按钮,它应该从图库中获取图像并将其发送到我想要的另一个活动显示我在其他活动布局中使用了imageview。我正在使用这个代码,画廊没有打开所以无法获取图像..正确我plz。
当前活动:
private static final int REQUEST_CODE = 1;
private Bitmap bitmap;
private ImageView imageView;
public void onClickPickImage(View view){
Intent intent = new Intent(this,GreetingCard.class);
intent.setType("image/*");
intent.putExtra("bmp_Image", bitmap);
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
InputStream stream = null;
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK)
try {
// recyle unused bitmaps
if (bitmap != null) {
bitmap.recycle();
}
stream = getContentResolver().openInputStream(data.getData());
bitmap = BitmapFactory.decodeStream(stream);
imageView.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (stream != null)
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
下一个活动:
ImageView imageResult = (ImageView) findViewById(R.id.image_result);
imageResult.setImageResource(getIntent().getIntExtra("bmp_Image",R.id.image_result));