Android的 - 如何设置墙纸图像? [英] Android - How to set the wallpaper image?

查看:137
本文介绍了Android的 - 如何设置墙纸图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  机器人 - 如何设置墙纸图像

Possible Duplicate:
Android - how to set the wallpaper image

我想要做的是,用一个形象的URI设置壁纸(不裁剪)

What i'm trying to do is, set the wallpaper using an image URI (no cropping)

我在Android的一个小白在开发和开发一般。 互联网已经让我失望......对提供code设置壁纸。

I'm a noob at dev on Android and dev in general. The internet has failed me... on providing code to set the wallpaper.

的dev的资源网站说,

yes the dev resource site says

公共无效setStream(InputStream中的数据)

但我不明白,一些样本code将极大地帮助我。

but i don't understand it, some sample code would greatly help me.

推荐答案

你可以使用这个code,如果你有图片的路径。

Hi you can use this code if You have Image path.

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,然后使用这个


if you have image URI then use this

wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);


让我知道,如果有任何问题。


Let me know if there is any issue .

这篇关于Android的 - 如何设置墙纸图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆