由网友(全世界最好听的闺蜜)分享简介:你能帮助我吗?我尝试过:的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;
}
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;
}
相关推荐
最新文章