Android - 如何设置壁纸图像?

发布于 2024-08-20 21:05:43 字数 397 浏览 23 评论 0原文

可能的重复:
Android - 如何设置壁纸图像

我正在尝试什么要做的是,使用图像 URI 设置壁纸(不裁剪)

我是 Android 开发人员和一般开发人员。 互联网让我失望...无法提供设置壁纸的代码。

开发资源网站说

public void setStream (InputStream data)

但我不明白,一些示例代码会对我有很大帮助。

Possible Duplicate:
Android - how to set the wallpaper image

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

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

yes the dev resource site says

public void setStream (InputStream data)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不知在何时 2024-08-27 21:05:43

您好,如果您有图像路径,您可以使用此代码。

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);

如果有任何问题请告诉我。

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);

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 .

长伴 2024-08-27 21:05:43

如果您有图像 URL,则可以使用流(抽象)打开它代表的资源:
新 URL("your.image.url.com").openStream()。此方法调用将返回一个 InputStream 类型的对象,您可以将其作为参数传递给 setStream() 方法。

如果您不想直接指定流,则可以打开远程流,创建位图,然后使用 WallpaperManager 实例或执行 context.setWallpaper(bitmap)(已弃用)将位图设置为壁纸。

作为参考,请查看 这个线程。

If you have the image URL you can open the resource it represent using the stream(abstraction):
new URL("your.image.url.com").openStream(). This method call will return an object of type InputStream which you can pass as an argument to setStream() method.

If you dont want to specify a stream directly, you can open the remote stream, create a Bitmap and then either use a WallpaperManager instance or do a context.setWallpaper(bitmap)(this is deprecated) to set your bitmap as the wallpaper.

For reference take a look at this thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文