无名商城论坛

搜索
查看: 396|回复: 0

[其他技术] iapp之图片控件直接显示网络地址图

[复制链接]

1万

主题

1万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
32464
发表于 2022-5-8 18:55:00 | 显示全部楼层 |阅读模式
iApp的图片控件默认是不支持显示网络地址图片的,但是我们在调用java的一些方法后可以直接让部分控件可以直接显示网络图片。
//首先新建一个Http.mjava文件写入以下代码
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.net.*;
import java.io.*;
import java.net.*;
import android.graphics.drawable.*;

//获取网络图片
    public static BitmapDrawable getInternetPicture(String UrlPath) {  
        Bitmap bm = null;  
        String urlpath = UrlPath;  
        try {  
            URL uri = new URL(urlpath);  
            HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
            connection.setRequestMethod("GET");  
            connection.setReadTimeout(5000);  
            connection.setConnectTimeout(5000);  
            connection.connect();  
            if (connection.getResponseCode() == 200) {  
                InputStream is = connection.getInputStream();  
                bm = BitmapFactory.decodeStream(is);  
            } else {
                bm = null;  
            }  
        } catch (MalformedURLException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
        return new BitmapDrawable(bm);  
        
}
//然后在.iyu界面里载入事件上写入以下代码
t()
{
    s bgurl = "
本帖隐藏的内容需要【资源会员】才可浏览,您需要升级才可浏览,点击这里升级【资源会员】
    call(bg,"mjava","Http.getInternetPicture",bgurl)
    ufnsui()
    {
        us(1,"background",bg)
    }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表