如何在Android上使用setImageUri()如何在、Android、setImageUri

由网友(全世界最好听的闺蜜)分享简介:你能帮助我吗?我尝试过:的ImageButton imgbt =(的ImageButton)findViewById(R.id.imgbutton);乌里imgUri = Uri.parse(/数据/数据​​/ MyFolder中/ myimage.png);imgbt.setImageUri(imgUri);但我...

你能帮助我吗?我尝试过:

 的ImageButton imgbt =(的ImageButton)findViewById(R.id.imgbutton);
乌里imgUri = Uri.parse(/数据/数据​​/ MyFolder中/ myimage.png);
imgbt.setImageUri(imgUri);
 

但我没有看到任何东西,只是一个空白按钮。

解决方案

 私人位图getImageBitmap(字符串URL){
        位图BM = NULL;
        尝试 {
            URL aURL =新的网址(URL);
            URLConnection的康恩= aURL.openConnection();
            conn.connect();
            InputStream的是= conn.getInputStream();
            的BufferedInputStream双=新的BufferedInputStream(是);
            BM = BitmapFactory.de codeStream(之二);
            bis.close();
            is.close();
       }赶上(IOException异常E){
           Log.e(TAG,错误获取位图,E);
       }
       返回BM;
    }
 

下一代 Android 系统要来了,除了兼容 刘海屏 ,还有哪些新功能

Can you help me please? I've tried :

ImageButton imgbt=(ImageButton)findViewById(R.id.imgbutton);
Uri imgUri=Uri.parse("/data/data/MYFOLDER/myimage.png");
imgbt.setImageUri(imgUri);

but I didn't see anything, simply a void button.

解决方案

    private Bitmap getImageBitmap(String url) {
        Bitmap bm = null;
        try {
            URL aURL = new URL(url);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();
       } catch (IOException e) {
           Log.e(TAG, "Error getting bitmap", e);
       }
       return bm;
    } 

阅读全文

相关推荐

最新文章