我下載的圖像與此代碼:大小從Drawable.getIntrinsicWidth錯誤的()
ImageGetter imageGetter = new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable drawable = null;
try {
URL url = new URL(source);
String path = Environment.getExternalStorageDirectory().getPath()+"/Android/data/com.my.pkg/"+url.getFile();
File f=new File(path);
if(!f.exists()) {
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
f=new File(f.getParent());
f.mkdirs();
FileOutputStream os = new FileOutputStream(path);
byte[] buffer = new byte[4096];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
os.close();
is.close();
}
drawable = Drawable.createFromPath(path);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Throwable t) {
t.printStackTrace();
}
if(drawable != null) {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
}
return drawable;
}
};
此圖片的大小爲20×20。但drawable.getIntrinsicWidth()和drawable.getIntrinsicHeight()的返回27和圖像看起來更大。我如何解決它?
這兩種解決方案都適用於我,但是,您更接近於新的API更改。再次感謝。 – ForceMagic