0
我需要從SD卡中獲取圖像並將其顯示在網格視圖中,並將所選圖像顯示在圖像視圖中。如何可能?獲取gridview中的SD卡圖像,並在另一個活動中顯示選定的圖像
我需要從SD卡中獲取圖像並將其顯示在網格視圖中,並將所選圖像顯示在圖像視圖中。如何可能?獲取gridview中的SD卡圖像,並在另一個活動中顯示選定的圖像
首先創建此意向,並開始對結果的活動:
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
然後在結果的活動處理是這樣的:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK) {
pickedImageUri = data.getData();
imgView.setImageUri(pickedImageUri);
}
您必須確保您引用imgView到佈局ID通過說明:
ImageView imgView = (ImageView)findViewById(R.id.iv_pickedpicture);
我希望這可以幫助。