下载并显示缩略图 [英] Download and show the Thumbnail

查看:188
本文介绍了下载并显示缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从URL中下载图片,SD卡/下载。
我尝试以显示其在ImageView的缩略图。
现在,我有如下code:

I try to download a picture from URL to SD card/Download. And I try to show its thumbnail in imageview. Now I had below code:

try {
Download(URL);  //download picture to SD card/Download
File myfile = new File(Environment.getExternalStorageDirectory() + "/Download/", filename);
Drawable photo = null; 
photo = Drawable.createFromPath(myfile.getPath());
imageview.setBackgroundDrawable(photo);
}

这显示了原始图片。
但是,当图象是大的。
发生的内存错误。
所以我想显示较小的图片。
我应该怎么做才能生成缩略图,并显示它?
或如何使用缩略图Android系统的产生?

It show the original picture. But when the picture is large. The memory error occurs. So I want to show the smaller picture. How should I do to generate the thumbnail and show it? Or how to use the thumbnail generate by Android system?

推荐答案

使用位图,喜欢的东西,

Use Bitmap, Something like,

    try     
    {
        Download(URL);  //download picture to SD card/Download

        final int THUMBNAIL_SIZE = 64;

        FileInputStream fis = new FileInputStream(Environment.getExternalStorageDirectory() + "/Download/", filename);
        Bitmap imageBitmap = BitmapFactory.decodeStream(fis);

        imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);
        imageview.setImageBitmap(imageBitmap);

    }
    catch(Exception ex) {

    }

这篇关于下载并显示缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆