From 9631cedb2ef52048d8f6cf88d468ef6c072e1f9f Mon Sep 17 00:00:00 2001 From: weishaoxiong Date: Tue, 12 Jul 2022 14:52:08 +0800 Subject: [PATCH] Signed-off-by: weishaoxiong fix:CreatePixelMap --- services/src/wallpaper_service.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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;