Android 如何使用截图或其他方式从URL设置相对布局背景图像?
我想从web URL设置布局背景图像 用截击、毕加索或其他方式 有没有办法设定这个 我在网站上找到了下面的代码,但不起作用Android 如何使用截图或其他方式从URL设置相对布局背景图像?,android,url,layout,Android,Url,Layout,我想从web URL设置布局背景图像 用截击、毕加索或其他方式 有没有办法设定这个 我在网站上找到了下面的代码,但不起作用 Bitmap myImage = getBitmapFromURL("http://looksok.files.wordpress.com/2011/12/me.jpg"); RelativeLayout rLayout=(RelativeLayout)findViewById(R.id.relativeLayout); //BitmapDrawable(obj) con
Bitmap myImage = getBitmapFromURL("http://looksok.files.wordpress.com/2011/12/me.jpg");
RelativeLayout rLayout=(RelativeLayout)findViewById(R.id.relativeLayout);
//BitmapDrawable(obj) convert Bitmap object into drawable object.
Drawable dr = new BitmapDrawable(myImage);
rLayout.setBackgroundDrawable(dr);
public Bitmap getBitmapFromURL(String imageUrl) {
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
请尝试此Android智能图像视图库
我使用以下链接从url设置图像:
如果您使用的是android studio,请在build.gradle文件中输入compile'com.squareup.picasso:picasso:2.5.2'并编译项目 然后你可以使用毕加索图书馆
Picasso.with(mContext)
.load("http://looksok.files.wordpress.com/2011/12/me.jpg")
.into(rLayout);
这将把图像从给定的url加载到rLayout中
参考:这是为图像视图设置图像,我想为布局设置图像,我的项目中已经在使用截图,如果你知道如何使用截图从URL设置相对布局背景,请解释,否则与其他库也可以。。但是我需要为相对布局设置图像你知道如何给那个图像加模糊吗?你知道如何给那个图像加模糊吗?@PrabhakarThota这是我在以前的项目中用过的模糊图像再一次有没有办法给背景图像加模糊像这样会给tansperency cc000000这样不,现在还不可能,你必须自己编辑一个位图,如代码所示。我刚刚发布了一个链接,我不知道怎么做,我试过了,没有影响。它只影响从drawable加载的图像,但在我的例子中,我从URL加载图像,这就是问题所在。。你能为这个解决方案提供任何代码吗?你知道如何使图像模糊吗??