diff --git a/services/src/wallpaper_service.cpp b/services/src/wallpaper_service.cpp index 9614160..455ce60 100644 --- a/services/src/wallpaper_service.cpp +++ b/services/src/wallpaper_service.cpp @@ -444,14 +444,19 @@ bool WallpaperService::MakeCropWallpaper(int wallpaperType) int32_t pictrueWidth = wallpaperPixelMap->GetWidth(); int pyScrWidth = GetWallpaperMinWidth(); int pyScrHeight = GetWallpaperMinHeight(); - if (pictrueHeight > pyScrHeight || pictrueWidth > pyScrWidth) { + bool bHeightFlag = false, bWidthFlag = false; + if (pictrueHeight > pyScrHeight) { decodeOpts.CropRect.top = (pictrueHeight - pyScrHeight)/HALF; - decodeOpts.CropRect.width = pyScrWidth; - decodeOpts.CropRect.left = (pictrueWidth - pyScrWidth)/HALF; - decodeOpts.CropRect.height = pyScrHeight; - decodeOpts.desiredSize.width = pyScrWidth; - decodeOpts.desiredSize.height = pyScrHeight; + bHeightFlag = true; } + if (pictrueWidth > pyScrWidth) { + decodeOpts.CropRect.left = (pictrueWidth - pyScrWidth)/HALF; + bWidthFlag = true; + } + decodeOpts.CropRect.height = bHeightFlag ? pyScrHeight : pictrueHeight; + decodeOpts.desiredSize.height = decodeOpts.CropRect.height; + decodeOpts.CropRect.width = bWidthFlag ? pyScrWidth : pictrueHeight; + decodeOpts.desiredSize.width = decodeOpts.CropRect.width; wallpaperPixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode); if (errorCode != 0) { ret = false;