我是android的noob,我想用SDcard中的文件設置ImageButton圖像。但是,getBitmap不會創建工作位圖。當我用剛創建的位圖設置ImageButton時,imageButton的尺寸會發生變化,但圖像不會出現。這真是令人沮喪,任何幫助解決這一問題,我都非常感謝。getBitmap方法爲什麼不能正常工作?
mycode的
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE:
// If the file selection was successful
if (resultCode == RESULT_OK) {
if (data != null) {
// Get the URI of the selected file
final Uri uri = data.getData();
try {
// Create a file instance from the URI
final File file = FileUtils.getFile(uri);
Toast.makeText(Profile_Barber.this,"File Selected: "+file.getAbsolutePath(), Toast.LENGTH_LONG).show();
Log.e("URI", uri.toString());//Returns: content://media/external/images/media/1834
Bitmap bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
if(bmp==null){
Log.e("BMP NULL", "This that bullshit!");
}else{
Log.e("BMP NOT NULL", bmp.toString()); //Returns: BMP NOT NULL [email protected]
profilepic.setImageBitmap(bmp);
}
} catch (Exception e) {
Log.e("FileSelectorTestActivity", "File select error", e);
e.printStackTrace();
}
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
您是否嘗試將位圖設置爲ImageView? – kvh
不,我沒有。它真的有區別,無論它是一個imageview或imageButton? – DollaBill
我的意思是,如果你可以在ImageView中製作它,那麼我們可以確保位圖很酷,我們可以尋找另一個原因。 – kvh