Android的 - 设置的墙纸,以适应手机屏幕尺寸墙纸、屏幕尺寸、手机、以适应

2023-09-13 01:56:14 作者:风绾梦境悠

我用的是最简单的code设置壁纸

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:

https://m.xsw88.com/allimgs/daicuo/20230913/762.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();
 }