2014-01-08 39 views
0

在url後面有一個高度爲80,寬度爲120px的圖像。因此,讓我取,Android中縮小圖像的奧祕

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和繪製:

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

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

突然我的形象是80x53像素。任何人都可以解釋爲什麼會發生這種情況,以及如何說服我的應用程序保持圖像的原始大小?

回答

1

我真的不知道如何使用可繪製對象解決您的問題,但是如果您可以嘗試使用位圖執行此操作。 正如我在自己的項目中使用的那樣,我從來沒有將這個問題與圖像大小關聯起來:

Bitmap bitmap = BitmapFactory.decodeStream(inputStream);