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 将图像设置为墙纸?
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
