From 48c92b5fe7e8ab7418f37d810bb32f50ec0c1dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E5=8F=8C=E6=98=8E?= Date: Thu, 26 Sep 2024 03:11:39 +0000 Subject: [PATCH] update library/src/main/ets/downsampling/Downsampler.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 田双明 --- .../src/main/ets/downsampling/Downsampler.ets | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/src/main/ets/downsampling/Downsampler.ets b/library/src/main/ets/downsampling/Downsampler.ets index a94000f..517fc34 100644 --- a/library/src/main/ets/downsampling/Downsampler.ets +++ b/library/src/main/ets/downsampling/Downsampler.ets @@ -27,9 +27,10 @@ export interface calculateScaleType { targetHeight: number } + export class Downsampler { calculateScaling( - typeValue: string, + typeValue: string |null, sourceWidth: number, //原始宽高 sourceHeight: number, //原始宽高 requestWidth: number, //请求宽高 @@ -38,7 +39,7 @@ export class Downsampler { ): calculateScaleType { if (sourceHeight <= 0 || sourceWidth <= 0) { - throw new Error("非法宽高 sourceHeight sourceWidth") + throw new Error(`Invalid width and height, sourceHeight:${sourceHeight}+ sourceWidth:${sourceWidth}`) } let downsampler = this.getDownsampler(downsampType); let exactScaleFactor: number = @@ -46,7 +47,7 @@ export class Downsampler { let rounding: SampleSizeRounding = downsampler.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType); //采样类型 //原始宽高和缩放系数的乘积 - let outSize = { + let outSize:Size = { width: this.round(exactScaleFactor * sourceWidth), height: this.round(exactScaleFactor * sourceHeight) } @@ -64,11 +65,16 @@ export class Downsampler { targetHeight: Math.floor(sourceHeight / scaleFactor) } } else if (typeValue === "webp") { - targetWidth = Math.round(sourceWidth / scaleFactor); - targetHeight = Math.round(sourceHeight / scaleFactor); + return { + targetWidth: Math.round(sourceWidth / scaleFactor), + targetHeight: Math.round(sourceHeight / scaleFactor) + } } else { - targetWidth = sourceWidth / scaleFactor; - targetHeight = sourceHeight / scaleFactor; + return { + targetWidth: sourceWidth / scaleFactor, + targetHeight: sourceHeight / scaleFactor + + } } }