From b2af4e1958f6c736a9a6a4544ce7d5bc410cf6a9 Mon Sep 17 00:00:00 2001 From: tsm Date: Fri, 13 Sep 2024 14:31:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=8D=E9=87=87=E6=A0=B7=E5=AE=BD=E9=AB=98?= =?UTF-8?q?=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tsm --- library/src/main/ets/downsampling/Downsampler.ets | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/src/main/ets/downsampling/Downsampler.ets b/library/src/main/ets/downsampling/Downsampler.ets index 033d148..6e40317 100644 --- a/library/src/main/ets/downsampling/Downsampler.ets +++ b/library/src/main/ets/downsampling/Downsampler.ets @@ -37,8 +37,8 @@ export class Downsampler { downsampType: DownsampleStrategy | undefined, ): calculateScaleType { const fileType = typeValue //获取图片类型 - let targetWidth: number | null = null; - let targetHeight: number | null = null; + let targetWidth: number | null = null;//降采样之后的宽 + let targetHeight: number | null = null;//降采样之后的高 if (sourceHeight <= 0 || sourceWidth == undefined || sourceWidth == null || sourceWidth <= 0) { throw new Error("Cannot found width or height") } @@ -47,14 +47,14 @@ export class Downsampler { } let downsampler = this.getDownsampler(downsampType); let exactScaleFactor : number = downsampler.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType); - let rounding: SampleSizeRounding= downsampler.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType); + let rounding: SampleSizeRounding= downsampler.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight, downsampType);//采样类型 if (exactScaleFactor==undefined|| exactScaleFactor <= 0 ) { throw new Error("Cannot round with exactScaleFactor"); } - let outWidth: number = this.round(exactScaleFactor * sourceWidth); - let outHeight: number = this.round(exactScaleFactor * sourceHeight); - let widthScaleFactor = sourceWidth / outWidth; - let heightScaleFactor = sourceHeight / outHeight; + let outWidth: number = this.round(exactScaleFactor * sourceWidth);//原始宽和缩放系数的乘积 + let outHeight: number = this.round(exactScaleFactor * sourceHeight);//原始高和缩放系数的乘积 + let widthScaleFactor = sourceWidth / outWidth;//计算的缩放因子 + let heightScaleFactor = sourceHeight / outHeight;//计算的缩放因子 let scaleFactor = rounding ==SampleSizeRounding.QUALITY ? Math.max(widthScaleFactor, heightScaleFactor) : Math.min(widthScaleFactor, heightScaleFactor) //将整型的缩放因子转换为2的次幂采样大小 let powerOfTwoSampleSize: number = scaleFactor;