바탕 화면의 비트 맵을 설정하려고하지만 효과가 없습니다. 잊지 마세요, 또한비트 맵에서 바탕 화면으로 크기 조정 크기 조정 setWallpaper
// Get display dimensions
final DisplayMetrics metrics = getResources().getDisplayMetrics();
final int displayWidth = metrics.widthPixels;
final int displayHeight = metrics.heightPixels;
// Here I'm decoding a resource, just for the example sake
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.picture);
// obtain the original Bitmap's dimensions
final int originalWidth = bitmap.getWidth();
final int originalHeight = bitmap.getHeight();
// Obtain the horizontal and vertical scale factors
final float horizontalScaleFactor = (float) originalWidth/(float) displayWidth;
final float verticalScaleFactor = (float) originalHeight/(float) displayHeight;
// Get the biggest scale factor to use in order to maintain original image's aspect ratio
final float scaleFactor = Math.max(verticalScaleFactor, horizontalScaleFactor);
final int finalWidth = (int) (originalWidth/scaleFactor);
final int finalHeight = (int) (originalHeight/scaleFactor);
// Create the final bitmap
final Bitmap wallpaperBmp = Bitmap.createScaledBitmap(
bitmap, finalWidth, finalHeight, true);
// Recycle the original bitmap
bitmap.recycle();
// Finally set it as wallpaper
try {
final WallpaperManager wallMan = WallpaperManager.getInstance(this);
wallMan.setBitmap(wallpaperBmp);
} catch (IOException e) {
Log.e("Wallpaper", "Something went wrong: " + e.toString());
wallpaperBmp.recycle();
}
: 코드를 여기에 <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/> <uses-permission android:name="android.permission.SET_WALLPAPER" />
BTW. 배경 화면이 너무 크고 확대되었습니다. | – ramzixp
'createScaledBitmap()'을 대신 사용해 보셨습니까? – DeeV
예, 시도했습니다 ... 동일한 효과, 그것은 setWallpaper 자체 해상도를 설정하는 것 같습니다 : | – ramzixp