demo修改
This commit is contained in:
parent
6c8e873b80
commit
9c356112e2
|
@ -6,7 +6,7 @@ export class CenterInside{
|
||||||
getScaleFactor(sourceWidth:number, sourceHeight:number,requestWidth:number, requestHeight:number):number {
|
getScaleFactor(sourceWidth:number, sourceHeight:number,requestWidth:number, requestHeight:number):number {
|
||||||
return Math.min(1,this.getScale(sourceWidth, sourceHeight, requestWidth, requestHeight))
|
return Math.min(1,this.getScale(sourceWidth, sourceHeight, requestWidth, requestHeight))
|
||||||
}
|
}
|
||||||
getSampleSizeRounding(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):SampleSizeRounding {
|
getSampleSizeRounding(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):number{
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
getScale(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
getScale(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||||
|
@ -80,9 +80,6 @@ export class Atleast implements BaseDownsampling{
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
export class CenterOutside implements BaseDownsampling{
|
export class CenterOutside implements BaseDownsampling{
|
||||||
static getSampleSizeRounding(orientedSourceWidth: number, orientedSourceHeight: number, targetWidth: number, targetHeight: number): SampleSizeRounding {
|
|
||||||
throw new Error('Method not implemented.')
|
|
||||||
}
|
|
||||||
getName(){
|
getName(){
|
||||||
return "CenterOutside"
|
return "CenterOutside"
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class Downsampler {
|
||||||
targetHeight = request.size.height;
|
targetHeight = request.size.height;
|
||||||
targetWidth = request?.size.width;
|
targetWidth = request?.size.width;
|
||||||
} else {
|
} else {
|
||||||
console.log('宽高都不存在')
|
throw new Error("Cannot found width or height ");
|
||||||
}
|
}
|
||||||
if (sourceWidth <= 0 || sourceHeight <= 0) return;
|
if (sourceWidth <= 0 || sourceHeight <= 0) return;
|
||||||
let orientedSourceWidth = sourceWidth;
|
let orientedSourceWidth = sourceWidth;
|
||||||
|
@ -36,13 +36,14 @@ export class Downsampler {
|
||||||
orientedSourceHeight = sourceWidth;
|
orientedSourceHeight = sourceWidth;
|
||||||
}
|
}
|
||||||
/*安卓的模式*/
|
/*安卓的模式*/
|
||||||
let exactScaleFactor: number =new FitCenter().getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
let exactScaleFactor: number =new FitCenter()
|
||||||
|
.getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
||||||
if (exactScaleFactor <= 0) {
|
if (exactScaleFactor <= 0) {
|
||||||
throw new Error("Cannot round with exactScaleFactor");
|
throw new Error("Cannot round with exactScaleFactor");
|
||||||
}
|
}
|
||||||
console.log('exactScaleFactor', exactScaleFactor)
|
|
||||||
/*安卓的模式*/
|
/*安卓的模式*/
|
||||||
let rounding: SampleSizeRounding =new FitCenter().getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
let rounding: SampleSizeRounding =new FitCenter()
|
||||||
|
.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
||||||
if (rounding == null) {
|
if (rounding == null) {
|
||||||
throw new Error("Cannot round with null rounding");
|
throw new Error("Cannot round with null rounding");
|
||||||
}
|
}
|
||||||
|
@ -50,7 +51,9 @@ export class Downsampler {
|
||||||
let outHeight: number = this.round(exactScaleFactor * orientedSourceHeight);
|
let outHeight: number = this.round(exactScaleFactor * orientedSourceHeight);
|
||||||
let widthScaleFactor = Math.floor(orientedSourceWidth / outWidth);
|
let widthScaleFactor = Math.floor(orientedSourceWidth / outWidth);
|
||||||
let heightScaleFactor = Math.floor(orientedSourceHeight / outHeight);
|
let heightScaleFactor = Math.floor(orientedSourceHeight / outHeight);
|
||||||
let scaleFactor = rounding == SampleSizeRounding.MEMORY ? Math.max(widthScaleFactor, heightScaleFactor) : Math.min(widthScaleFactor, heightScaleFactor)
|
let scaleFactor = rounding == SampleSizeRounding.MEMORY ?
|
||||||
|
Math.max(widthScaleFactor, heightScaleFactor) :
|
||||||
|
Math.min(widthScaleFactor, heightScaleFactor)
|
||||||
// 将整型的缩放因子转换为2的次幂采样大小
|
// 将整型的缩放因子转换为2的次幂采样大小
|
||||||
let powerOfTwoSampleSize: number = 0;
|
let powerOfTwoSampleSize: number = 0;
|
||||||
powerOfTwoSampleSize = Math.max(1,this.highestOneBit(scaleFactor))
|
powerOfTwoSampleSize = Math.max(1,this.highestOneBit(scaleFactor))
|
||||||
|
@ -70,52 +73,18 @@ export class Downsampler {
|
||||||
} else if (fileType == "PNG") {
|
} else if (fileType == "PNG") {
|
||||||
powerOfTwoWidth = Math.floor(orientedSourceWidth / powerOfTwoSampleSize);
|
powerOfTwoWidth = Math.floor(orientedSourceWidth / powerOfTwoSampleSize);
|
||||||
powerOfTwoHeight = Math.floor(orientedSourceHeight / powerOfTwoSampleSize);
|
powerOfTwoHeight = Math.floor(orientedSourceHeight / powerOfTwoSampleSize);
|
||||||
console.log('执行了没', powerOfTwoHeight, powerOfTwoWidth)
|
|
||||||
} else if (fileType == "WEBP") {
|
} else if (fileType == "WEBP") {
|
||||||
powerOfTwoWidth = Math.round(orientedSourceWidth / powerOfTwoSampleSize);
|
powerOfTwoWidth = Math.round(orientedSourceWidth / powerOfTwoSampleSize);
|
||||||
powerOfTwoHeight = Math.round(orientedSourceHeight / powerOfTwoSampleSize);
|
powerOfTwoHeight = Math.round(orientedSourceHeight / powerOfTwoSampleSize);
|
||||||
} else if (
|
} else if (orientedSourceWidth % powerOfTwoSampleSize != 0 || orientedSourceHeight % powerOfTwoSampleSize != 0) {
|
||||||
orientedSourceWidth % powerOfTwoSampleSize != 0 || orientedSourceHeight % powerOfTwoSampleSize != 0) {
|
|
||||||
|
|
||||||
|
|
||||||
// let dimensions; number[] = this.getDimensions(imageReader, options, decodeCallbacks,bitmapPool);
|
|
||||||
// powerOfTwoWidth = dimensions[0];
|
|
||||||
// powerofTwoHeight = dimensions[1];
|
|
||||||
} else {
|
} else {
|
||||||
powerOfTwoWidth = orientedSourceWidth / powerOfTwoSampleSize;
|
powerOfTwoWidth = orientedSourceWidth / powerOfTwoSampleSize;
|
||||||
powerOfTwoHeight = orientedSourceHeight / powerOfTwoSampleSize;
|
powerOfTwoHeight = orientedSourceHeight / powerOfTwoSampleSize;
|
||||||
}
|
}
|
||||||
// Let adjustedScaleFactor = downsampleStrategy.getScaleFactor(powerOfTwoWidth, powerOfTwoHeight, targetWidth, targetHeight);
|
|
||||||
// Density scaling is only supported if inBitmap is null prior to KitKat. Avoid setting
|
|
||||||
// densities here so we calculate the final Bitmap size correctly.
|
|
||||||
// if (Build.VERSION,SDK_INT >=Build.VERSION_CODES.KITKAT) {
|
|
||||||
// options.inTargetDensity = this.adjustTargetDensityForError(adjustedScaleFactor);
|
|
||||||
// options,inDensity = this.getDensityMultiplier(adjustedScaleFactor);
|
|
||||||
//}
|
|
||||||
// if (this.isScaling(options)){
|
|
||||||
// options.inScaled = true;
|
|
||||||
// }else {
|
|
||||||
// options.inDensity = options.inTargetDensity =0;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
let a: ESObject = { "targetWidth": powerOfTwoWidth, "targetHeight": powerOfTwoHeight }
|
let a: ESObject = { "targetWidth": powerOfTwoWidth, "targetHeight": powerOfTwoHeight }
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
//decodeStream(imageReader:ImageReader, options: ESObject, callbacks: DecodeCallbacks, bitmapPool: ESObject) {
|
|
||||||
//if (!options.inJustDecodeBounds){
|
|
||||||
// callbacks.onObtainBounds();
|
|
||||||
// imageReader.stopGrowingBuffers();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// getDimensions(imageReader: ImageReader, options: ESObject, decodeCallbacks: DecodeCallbacks, bitmapPool: ESObject):number[] {
|
|
||||||
// options.inJustDecodeBounds = true;
|
|
||||||
// this.decodeStream(imageReader, options, decodeCallbacks, bitmapPool);
|
|
||||||
// options.inJustDecodeBounds =false;
|
|
||||||
// return new Array(options.outWidth, options,outHeight);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
highestOneBit(i: number): number {
|
highestOneBit(i: number): number {
|
||||||
i |= (i >> 1);
|
i |= (i >> 1);
|
||||||
i |= (i >> 2);
|
i |= (i >> 2);
|
||||||
|
|
Loading…
Reference in New Issue