在android中缩小图像的谜团

时间:2014-01-08 18:57:25

标签: android size drawable

在网址后面有一个高度为80,宽度为120px的图像。所以让我拿它:

private InputStream fetch(String url) throws MalformedURLException, IOException 
{
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    HttpResponse response = httpClient.execute(request);
    return response.getEntity().getContent();
}

我得到了我想要的InputStream和drawable:

InputStream is = fetch(url);
Drawable drawable = Drawable.createFromStream(is, "");

int height = drawable.getIntrinsicHeight();
int width = drawable.getIntrinsicWidth();

突然我的图像是80x53像素。任何人都可以解释为什么会发生这种情况以及如何说服我的应用程序保留图像的原始大小?

1 个答案:

答案 0 :(得分:1)

我不知道如何使用Drawable对象解决您的问题,但是如果您可以尝试使用Bitmap执行此操作。 在我自己的项目中使用时,我从来没有遇到图像大小的问题:

Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
相关问题