【发布时间】:2013-02-05 11:39:35
【问题描述】:
我正在尝试在 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;
}
}
【问题讨论】:
标签: android image drawable image-size