Crop wallpapers to screen size #24
Replies: 2 comments
-
|
So just to confirm, you want to be able to crop the image, but take a center cut from the image? This is something I have wanted to improve myself as I notice it in some of the wallpapers. Currently this is the crop function: app/src/main/java/org/cssnr/remotewallpaper/ui/home/HomeFragment.kt#L276 fun scaleAndCropCenter(src: Bitmap, targetWidth: Int, targetHeight: Int): Bitmap {
// targetWidth: WallpaperManager.desiredMinimumWidth
// targetHeight: WallpaperManager.desiredMinimumHeight
Log.d("Cropper", "target W=$targetWidth H=$targetHeight")
val srcWidth = src.width
val srcHeight = src.height
Log.d("Cropper", "src W=$srcWidth H=$srcHeight")
val scale = maxOf(
targetWidth.toFloat() / srcWidth,
targetHeight.toFloat() / srcHeight
)
Log.d("Cropper", "scale: $scale")
val scaledWidth = (srcWidth * scale).toInt()
val scaledHeight = (srcHeight * scale).toInt()
Log.d("Cropper", "scaled W=$scaledWidth H=$scaledHeight")
val scaledBitmap = src.scale(scaledWidth, scaledHeight)
val x = (scaledWidth - targetWidth) / 2
val y = (scaledHeight - targetHeight) / 2
Log.d("Cropper", "x=$x y=$y")
return Bitmap.createBitmap(scaledBitmap, x, y, targetWidth, targetHeight)
}The result on a 1280x720 device: I will play around with this when I get some time. I am open to any suggestions tho. |
Beta Was this translation helpful? Give feedback.
-
|
yes exactly, I have the following theory in mind: Lets assume The device dimensions are
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
First of all, very cool app. It's exactly what I was looking for.
I have a feature request in mind. If a wallpaper does not match the screen dimensions it becomes scrolled to the side (especially if its landscape) for parallax. If I set the wallpaper from the android wallpaper picker I have the option to center it manually.
I see there is a crop wallpaper feature for smaller dimensions in the app already, which is great.
But the reverse would be really cool for achieving this centering.
Beta Was this translation helpful? Give feedback.
All reactions