android 屏幕最小宽度_Android的 - 设置的墙纸,以适应手机屏幕尺寸

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.

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?

EDIT:

Few screens:

Images from menu, before scale and after scale:

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

Any ideas??

解决方案

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();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值