Android - 如何设置壁纸图像?
可能重复:
Android - how to set the wallpaper imageAndroid - 如何设置壁纸图像?
我想要做的是,使用图像URI(不裁剪)
我在一个小白设置壁纸在Android和开发一般的开发。 互联网已经失败了我......提供代码来设置壁纸。
是的开发资源网站说
public void setStream (InputStream data)
,但我不明白,一些示例代码,将极大地帮助我。
如果您有图像URL,则可以使用流(抽象)打开它表示的资源: new URL("your.image.url.com").openStream()
。此方法调用将返回类型为InputStream
的对象,您可以将其作为参数传递给setStream()
方法。
如果您不想直接指定流,可以打开远程流,创建一个位图,然后使用WallpaperManager实例或执行context.setWallpaper(bitmap)
(这已弃用)将您的位图设置为壁纸。
仅供参考请看this帖子。
这是我目前的代码.. InputStream is = getContentResolver()。openInputStream(imageUri); bgImage = BitmapFactory.decodeStream(is); 上下文context = this.getBaseContext(); context.setWallpaper(bgImage);在bgImage(行2和4)和getBaseContext()(第3行)' 错误 也最新一个URI和URL之间的差异? 我得到的简短答案是“一个URL是一个URI,但是,一个URI不是一个URL” – 2010-02-05 15:51:21
好吧我修复了第2和第4行的错误,我没有定义位图bgImage。但仍然在getBaseContext上的错误() – 2010-02-05 17:01:42
你知道你可以传递一个活动作为上下文的实例吗?没有必要做一个this.getBaseContext()你可以传递当前活动或上下文对象的实例,如果你有一个[“this”将是一个有效的上下文对象] – Samuh 2010-02-08 05:42:46
嗨如果您有图片路径,您可以使用此代码。
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
System.out.println("Hi I am try to open Bit map");
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);
,如果你有像然后使用URI这个
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
让我知道如果有任何问题。
这条线的用法是什么? wallpaperDrawable = wallpaperManager.getDrawable(); – 2014-02-25 16:11:04
相关:[Android的 - 如何设置壁纸图像](http://stackoverflow.com/questions/1964193/android-how-to-set-the-wallpaper-image) – McDowell 2011-05-18 10:36:41