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;