Download and show the Thumbnail

后端 未结 2 997
青春惊慌失措
青春惊慌失措 2021-01-28 22:58

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 pi         


        
相关标签:
2条回答
  • 2021-01-28 23:18

    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) {
    
        }
    
    0 讨论(0)
  • 2021-01-28 23:26

    From the Shown Code

    Try this instead your last 2 lines

    Bitmap photo = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(myfile.getPath()),60,60,true);
    imageview.setImageBitmap(photo);
    

    And if you have made any objects for Bitmap/String/Stream in your Download() function free them calling System.gc();

    And I hope this will work.

    0 讨论(0)
提交回复
热议问题