Image download code works for all image format, issues with PNG format rendering

后端 未结 1 986
耶瑟儿~
耶瑟儿~ 2020-12-20 05:46

I am using the code below to download and show image from server to my ImageView

import java.io.IOException;
import java.io.InputStream;
import java.net.Http         


        
相关标签:
1条回答
  • 2020-12-20 05:51

    I dont know it will be a solution for you or not

    But you can use a Drawable instead of Bitmap

    Here is the code

    void downloadFile(String fileUrl) {
    try{
          InputStream is = (InputStream) new URL(fileUrl).getContent();
          Drawable d = Drawable.createFromStream(is, "src name");
          imgView.setImageDrawable(d);            
            } catch (IOException e) {
                e.printStackTrace();                
            }
    
    }
    

    This will show a png correctly

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