我正在从图库中挑选图像并在 ImageView 上显示图像。我能够成功地做到这一点。我的问题是,当我尝试设置从相机(.jpg 图像)捕获的图像时,它们没有显示在 imageview 中,只是出现了一个空白屏幕。即使是 .jpg 类型的图像也能成功显示,这些图像不是从相机捕获的。无法理解原因,可能是由于尺寸较大。请帮助以下是我的代码:
public class ImagePick extends Activity {
private Bitmap bitmap;
private ImageView imv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_upload);
imv = (ImageView) findViewById(R.id.targetimage);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 0);
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex); // file path of selected image
cursor.close();
// Convert file path into bitmap image using below line.
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
// put bitmapimage in your imageview
imv.setImageBitmap(yourSelectedImage);
}
}
}
}
提前致谢