首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从位图裁剪和调整大小的WallpaperManager意图

从位图裁剪和调整大小的WallpaperManager意图
EN

Stack Overflow用户
提问于 2016-01-23 13:31:40
回答 2查看 828关注 0票数 3

现在我们正在使用下面的代码从一些加载的图像中设置墙纸。

代码语言:javascript
复制
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
     myWallpaperManager.setBitmap(bitmap);
} catch (IOException e) {                                
  e.printStackTrace();
}
Toast.makeText(this, R.string.set_wallpaper_complete_toast,Toast.LENGTH_SHORT).show();
return true;

我们如何在上面的代码中使用getCropAndSetWallpaperIntent(Uri imageUri),以便它会询问设置墙纸和裁剪它的选项。

EN

回答 2

Stack Overflow用户

发布于 2016-01-23 14:23:56

代码语言:javascript
复制
    public Uri getImageUri(Context inContext, Bitmap inImage) {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
      String path = Images.Media.insertImage(inContext.getContentResolver(), 
inImage, "Title", null);
      return Uri.parse(path);
    } 

然后,

代码语言:javascript
复制
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
WallpaperManager myWallpaperManager
              = WallpaperManager.getInstance(getApplicationContext());
                try { 
                   Uri myImageUri = getImageUri(bitmap);
                    Intent intent = new Intent(myWallpaperManager.getCropAndSetWallpaperIntent(myImageUri));
                } catch (IOException e) {
                    // TODO Auto-generated catch block 
                    e.printStackTrace();
                    return false;
                } 
                Toast.makeText(
                        this, R.string.set_wallpaper_complete_toast,Toast.LENGTH_SHORT).show();
                return true; 
票数 1
EN

Stack Overflow用户

发布于 2019-08-04 22:21:38

使用以下内容

代码语言:javascript
复制
val path: String = MediaStore.Images.Media.insertImage(contentResolver, bitmap, "wallpaper.jpg", null)
        val intent = Intent(wallpaperManager.getCropAndSetWallpaperIntent(Uri.parse(path)))
        startActivity(intent)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34959999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档