如何在Android上使用setImageUri() [英] How to use setImageUri() on Android
本文介绍了如何在Android上使用setImageUri()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能帮助我吗?我尝试过:
的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;
}
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;
}
这篇关于如何在Android上使用setImageUri()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文