Android - 设置壁纸以适合手机屏幕尺寸 [英] Android - set wallpaper to fit phone screen size

查看:36
本文介绍了Android - 设置壁纸以适合手机屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用最简单的代码来设置wallpaper:

I am using a simplest code to set wallpaper:

Bitmap bmap2 = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.a));

getApplicationContext().setWallpaper(bmap2);

当图像尺寸大于屏幕尺寸时会出现问题.我只能看到输入图片的一部分.

And the problem occur when image size is bigger than screen size. I can see only the part of input picture.

我尝试调整像 createScaledBitmap 这样的方法,它可以工作,但不是我想要的.createScaledBitmap 正在调整位图的大小,而不是图片的大小,只是分辨率(只是搞砸了图片的质量,而不是作为壁纸加载到手机的图片大小).

I tried resizing methods like createScaledBitmap and it works, but not like I want. createScaledBitmap is resizing bitmap, but not size of picture, just resolution (just mess up the quality of picture, not picture size loaded to phone as wallpaper).

有谁知道如何缩小图像的大小,而不是分辨率?

Does anyone know how to scale down the size of image, not a resolution?

几个屏幕:

菜单中的图像,缩放前和缩放后:

Images from menu, before scale and after scale:

http://zapodaj.net/14097596e4251.png.html

如您所见,只有缩放分辨率,而不是图片大小.

So as you can see there is only scaled resolution, not size of picture.

有什么想法吗??

推荐答案

作者的回答在评论里,但是没有人看到评论,我复制到这里:

Answer from the author is in the comments, but as nobody see comments, I copy it here:

Bitmap bmap2 = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.paper));

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels; 
int width = metrics.widthPixels;
Bitmap bitmap = Bitmap.createScaledBitmap(bmap2, width, height, true); 

WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this); 
 try {
  wallpaperManager.setBitmap(bitmap);
 } catch (IOException e) {
  e.printStackTrace();
 }

这篇关于Android - 设置壁纸以适合手机屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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