0
我打算在Android中獲取圖像的寬度和高度,並相應地加載購買我的下面的代碼在2.3.3工作正常,但是當我測試更高版本(4.0)其高度和寬度是給空指針異常......下面是我的代碼...可繪製的高度和寬度不工作在Android ICS
Drawable drawable = null;
drawable = LoadImageFromWebOperations(logo_url.replace(" ", "%20"));
System.out.println("Width" + drawable.getMinimumWidth());
System.out.println("Height" + drawable.getMinimumHeight());
int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, drawable.getMinimumWidth(), mCtx.getResources().getDisplayMetrics());
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, drawable.getMinimumHeight(), mCtx.getResources().getDisplayMetrics());
client_logo.setMinimumHeight(height);
client_logo.setMinimumWidth(width);
client_logo.setImageDrawable(drawable);
public Drawable LoadImageFromWebOperations(String url){
System.out.println(url);
try{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return (d);
}catch (Exception e) {
//System.out.println("Exc="+e);
return null;
}
}
工作了很長時間...我的網絡操作加載到後臺本身.... – user1051599