[这是我的代码。请提供完整的代码。重新启动应用程序后应显示已接收的图像。谢谢] [1]
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
try {Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageBitmap(bitmap);
String[] filePathColon={MediaStore.Images.Media.DATA};
Cursor cursr=getContentResolver().query(uri, filePathColon, null, null, null);
cursr.moveToFirst();
int columnindex=cursr.getColumnIndex(filePathColon[0]);
final String picturepath=cursr.getString(columnindex);
cursr.close();
b1= (Button) findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(edit_student.this,student.class);
intent.putExtra("imagePath",picturepath );
startActivity(intent);}});
} catch (IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
将图像Uri发送到第二个活动,如下所示:
@override
public void onClick(View v){
Intent intent = new Intent(getApplicationContext(),student.class);
intent.putParceleableExtra("imageUri",uri);
startActivity(intent);
}
在你的SecondActivity onCreate()获取意图并获取uri,从uri创建一个位图对象并将其设置为图像视图。
Uri retreivedUri = getIntent().getParceleableExra("imageUri");