我想設置從Android畫廊選擇的圖像。 我使用此代碼來獲取選定的圖像。如何將圖像從一個活動發送到從Android Gallery中選擇的另一個活動?
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
//startActivity(intent);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);
而且onActivityResult方法是這樣的:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 10 && resultCode == Activity.RESULT_OK) {
Uri contentUri = data.getData();
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String tmppath = cursor.getString(column_index);
Bitmap croppedImage = BitmapFactory.decodeFile(tmppath);
go.setVisibility(View.VISIBLE);
//canvas.drawBitmap(kangoo, 130, 100, null);
//previewImage.setVisibility(View.VISIBLE);
imageSrc.setImageBitmap(croppedImage); //set to your imageview
}
}
現在,我想從圖庫中選擇圖片,並將其發送到另一個活動。那麼怎麼可能用上面的代碼? 謝謝。
謝謝。我知道了。 –