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

查看:148
本文介绍了如何从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???????

推荐答案

步骤1:获取附加到ImageView的图像。

Step 1: Get the image attached to the ImageView.

Setp 2:将该图片设为壁纸。

Step 3: AndroidManifest.xml 中添加权限以设置壁纸!

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

对于第1步检查< a href =https://stackoverflow.com/a/8306648/1773155>这个答案!

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天全站免登陆