-1
我想在ImageView的選擇從SD卡,並顯示用戶照片安卓:從SD卡setImageBitmap不行
我的代碼:
try {
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
}
catch (IOException e) {
e.printStackTrace();
}
imgOne.setImageBitmap(bm);
但是這個代碼不工作
此代碼爲onActivityResult選擇用戶後照片
我的課程:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
Log.i("error", "" + requestCode);
final ImageView imgOne = (ImageView) G.currentActivity.findViewById(R.id.imgOne);
if (requestCode == 1) {
Bitmap bm = null;
if (data != null) {
try {
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
//ByteArrayOutputStream bytes = new ByteArrayOutputStream();
//bm.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
//bm = Bitmap.createScaledBitmap(bm, 600, 600, true);
}
catch (IOException e) {
e.printStackTrace();
}
imgOne.setImageBitmap(bm);
Log.i("error", "" + bm);
}
}
}
}
是你用意向選擇圖像? –
是的,這個代碼經過用戶選擇並保存到數據 – Mohammad
可以發佈您的onActivityResult代碼 –