У меня есть Bitmap
, который нужно установить как Изображение экрана блокировки Android
Я могу установить Bitmap
для экрана блокировки, используя:
WallpaperManager wpm = WallpaperManager.getInstance(getApplicationContext());
//method signature: setBitmap (Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which)
wpm.setBitmap(theBitmap, null, true, FLAG_LOCK);
Проблема в том, что Bitmap
растягивается на экране блокировки и не сохраняет соотношение сторон.
Я пытался изменить размер Bitmap
до размеров экрана устройства, ноэто тоже не работает:
DisplayMetrics dimension = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dimension);
int screenWidth = dimension.widthPixels;
int screenHeight = dimension.heightPixels;
int imageWidth = bitmap.getWidth();
int imageHeight = bitmap.getHeight();
float scaleWidth = ((float) screenWidth) / imageWidth;
float scaleHeight = ((float) screenHeight) / imageHeight;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, imageWidth, imageHeight, matrix, false);
Кто-нибудь знает решение?