如何从 ImageView 将图像设置为墙纸? [英] How to set image as wallpaper from the ImageView?

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

问题描述

我有一个活动,其中有两个按钮和一个 ImageView.一个按钮是从手机的相机应用程序中获取图像并将其设置为 ImageView,另一个按钮是将该图像设置为主屏幕壁纸,所以我想要代码如何将此图像从 ImageView 设置为壁纸???????

I have an activity in which there are two Buttons and an ImageView. One button is to take image from the Camera application of the phone and set it to the ImageView, and other Button is to set that image as the Home screen wallpaper so i want the code how to set this image from the ImageView to the wallpaper???????

推荐答案

第一步: 获取附加到 ImageView 的图片.

Step 1: Get the image attached to the ImageView.

Setp 2:将该图像设置为墙纸.

第三步:AndroidManifest.xml中添加设置壁纸的权限!

Step 3: Add permission in the AndroidManifest.xml to set wallpaper!

对于第 1 步,请检查 这个答案!

For step 1 check This answer!

imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();

对于第 2 步:

WallpaperManager m=WallpaperManager.getInstance(this);

try {
    m.setBitmap(bmap);
} catch (IOException e) {
    e.printStackTrace();
}

对于第 3 步:也包括此权限.

For step 3: Include this permission too.

<uses-permission android:name="android.permission.SET_WALLPAPER" />

如果这不适合你,请告诉我!

Tell me if that does not works for you!

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

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