How to set image as wallpaper from the ImageView?(如何从 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 将图像设置为墙纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 ImageView 将图像设置为墙纸?


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01