.

调用java在图像控件中显示网络图片

2020/3/1 20:55:00  人气 729    iApp  
无意中在简书上看到了相关代码,在这里分享给大家!若要查看原文,请点这里!
新建webpic.mjava
代码:
import android.graphics.drawable.BitmapDrawable;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public static BitmapDrawable get(String url){
BitmapDrawable pic = null;
try{
URL u = new URL(url);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setRequestMethod(”GET”);
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
InputStream is = conn.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
pic = new BitmapDrawable(bmp);
is.close();
conn.disconnect();
}catch(Exception e){}
return pic;
}
iyu调用
代码:
t(){
s id=图像控件id
s img_url=”网络图片地址,双引号不能少”
call(img,”mjava”,”webpic.get”,img_url)
ufnsui(){
us(id, ”src”, img)
}
}
我TM直接御剑飞行(ID1000)加精此帖03-01 23:02   更多

. Hello,it’s me!

发表回复

   


  通知楼主

椅子

松少.03-01 21:32
@yucho:实测可用!!!#1
不错

回复只看TA

沙发

yucho.03-01 21:05
实测可用!!!

回复只看TA

.

帖子

刷新 换一批