我想在android中获取图像宽度和高度并相应地加载购买我的下面的代码在2.3.3中工作正常但是当我在更高版本(4.0)中测试时它的高度和宽度给出空指针异常......下面是我的代码...
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;
}
}