Merge branch 'master' of https://gitee.com/tianshuangming/ImageKnife
This commit is contained in:
commit
e137e2c836
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { RequestOption, ImageKnifeGlobal, ImageKnifeOption, ImageKnifeComponent } from '@ohos/libraryimageknife'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import { ImageKnifeData } from '@ohos/libraryimageknife'
|
||||
import {
|
||||
DownsampleNone,
|
||||
FitCenter
|
||||
} from '@ohos/imageknife/src/main/ets/components/inageknife/Downsampling/Downsamplestartegy'
|
||||
|
||||
// PixelMap transform示例
|
||||
let mRotate: number = 0;
|
||||
//let mUrl= "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVqqB" let murl = $r('app.media.pngSample'); let setting = new DownsampleNone()
|
||||
let mUrl = $r('app.media.pngSample');
|
||||
let setting = new DownsampleNone()
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct DownsamplingPage {
|
||||
@State url: string = "";
|
||||
@State mCropPixelMap?: PixelMap = undefined;
|
||||
@state mRoundPixelMap?: PixelMap = undefined;
|
||||
@State mCirclePixelMap?: PixelMap = undefined;
|
||||
@State mCircleBorderPixelMap?: PixelMap = undefined;
|
||||
@state mRotatePixelMap?: PixelMap = undefined;
|
||||
@state mSquarePixelMap?: PixelMap = undefined;
|
||||
@state mSquarePixelMap1?: PixelMap = undefined;
|
||||
@state mClipCenterPixelMap?: PixelMap = undefined;
|
||||
@state mClipBottomPixelMap?: PixelMap = undefined;
|
||||
@state mGrayscalePixelMap?: PixelMap = undefined;
|
||||
@state mBrightnessPixelMap?: PixelMap = undefined;
|
||||
@State mContrastPixelMap?: PixelMap = undefined;
|
||||
@state mInvertPixelMap?: PixelMap = undefined;
|
||||
@state mSepiaPixelMap?: PixelMap = undefined;
|
||||
@State mSketchPixelMap?: PixelMap = undefined;
|
||||
@state mBlurPixelMap?: PixelMap = undefined;
|
||||
@state mPixelPixelMap?: PixelMap = undefined;
|
||||
@State mSwirlPixelMap?: PixelMap = undefined;
|
||||
@State mMaskPixelMap?: PixelMap = undefined;
|
||||
@State mKuwaharaPixelMap?: PixelMap = undefined;
|
||||
@State mToonPixelMap?: PixelMap = undefined;
|
||||
@State mVignettePixelMap?: PixelMap = undefined;
|
||||
@State BytesNumber: number = 0;
|
||||
@State BytesNumber1: number = 0;
|
||||
@state imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.gifSample'),
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
downsampling: new DownsampleNone()
|
||||
};
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
|
||||
Column() {
|
||||
Column() {
|
||||
Column() {
|
||||
Text("大小:" + this.BytesNumber).fontColor(Color.Gray).fontsize(16);
|
||||
Button() {
|
||||
Text($r("app.string.trans_square")).fontSize(13).fontColor(Color.White)
|
||||
}
|
||||
.height(35)
|
||||
.width(120)
|
||||
.margin({ top: 10 })
|
||||
.onclick(() => {
|
||||
this.transformSquare();
|
||||
});
|
||||
if (this.mSquarePixelMap) {
|
||||
Image(this.mSquarePixelMap == undefined ? "" : this.mSquarePixelMap!)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
}
|
||||
}.margin({ top: 10 });
|
||||
}.margin({ bottom: 30 });
|
||||
Column() {
|
||||
Column() {
|
||||
Text("大小:" + this.BytesNumber1).fontColor(Color.Gray).fontSize(16);
|
||||
Button() {
|
||||
Text('降采样').fontsize(13).fontColor(Color.White)
|
||||
}
|
||||
.height(35).width(120)
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
this.transformSquare1();
|
||||
});
|
||||
if (this.mSquarePixelMap1) {
|
||||
Image(this.mSquarePixelMap1 == undefined ? '' : this.mSquarePixelMap1!)
|
||||
.objectFit(ImageFit.Fill)
|
||||
.width(200)
|
||||
.height(200)
|
||||
.margin({ top: 10 })
|
||||
}
|
||||
}.margin({ top: 10 });
|
||||
}.margin({ bottom: 30 });
|
||||
Column() {
|
||||
column() {
|
||||
Text("ImageKnifeComponent用法").fontColor(Color.Gray).fontSize(16);
|
||||
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 })
|
||||
.width(200)
|
||||
.height(200)
|
||||
}.margin({ top: 10 });
|
||||
}.margin({ bottom: 30 });
|
||||
}
|
||||
}.width('100%').height('100%');
|
||||
}
|
||||
|
||||
//正方形裁剪
|
||||
transformSquare() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(murl)
|
||||
.addListener({ callback: (err: BusinessError | string, data: ImageKnifeData) => {
|
||||
this.mSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
this.BytesNumber = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber()
|
||||
return false;
|
||||
} })
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
transformSquare1() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener({ callback: (err: BusinessError | string, data: ImageKnifeData) => {
|
||||
this.mSquarePixelMap1 = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
this.BytesNumber1 = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber()
|
||||
return false;
|
||||
} })
|
||||
.setImageViewsize({ width: 800, height: 500 })
|
||||
.downsampleStrategy(new FitCenter())
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
}
|
||||
|
||||
let ImageKnife = ImageKnifeGlobal.getInstance().getImageKnife();
|
|
@ -40,6 +40,10 @@ struct IndexFunctionDemo {
|
|||
console.log("优先级加载")
|
||||
router.pushUrl({ url: "pages/testPriorityComponent" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
Button("下采样加载")
|
||||
.onClick(() => {
|
||||
router.pushUrl({ url: "pages/DownsamplingPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
"pages/testImageKnifeHeic",
|
||||
"pages/testImageKnifeNetPlaceholder",
|
||||
"pages/testCustomDataFetchClientWithPage",
|
||||
"pages/testReuseAblePages"
|
||||
"pages/testReuseAblePages",
|
||||
"pages/DownsamplingPage"
|
||||
]
|
||||
}
|
|
@ -131,3 +131,5 @@ export { IDrawLifeCycle } from './src/main/ets/components/imageknife/interface/I
|
|||
|
||||
// 日志管理
|
||||
export { LogUtil } from './src/main/ets/components/imageknife/utils/LogUtil'
|
||||
/*下采样*/
|
||||
export {Downsampler} from './src/main/ets/components/imageknife/Downsampling/Downsampler'
|
|
@ -1,4 +1,7 @@
|
|||
export interface BaseDownsampling{
|
||||
import {lang}from '@kit.ArkTs';
|
||||
type ISendable = lang.ISendable;
|
||||
export interface BaseDownsampling extends ISendable{
|
||||
getName():string
|
||||
getScaleFactor(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):number
|
||||
|
||||
|
||||
|
|
|
@ -1,53 +1,91 @@
|
|||
import { BaseDownsampling } from './BaseDownsampling'
|
||||
|
||||
|
||||
@Sendable
|
||||
export class CenterInside{
|
||||
getScaleFactor(sourceWidth:number, sourceHeight:number,requestWidth:number, requestHeight:number):number {
|
||||
|
||||
return Math.min(1,FitCenter.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight))
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):SampleSizeRounding {
|
||||
return this.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight)==1
|
||||
?SampleSizeRounding.QUALITY
|
||||
:FitCenter.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight)
|
||||
|
||||
}
|
||||
getName() { return "CenterInside"}
|
||||
getScaleFactor(sourceWidth:number, sourceHeight:number,requestWidth:number, requestHeight:number):number {
|
||||
return Math.min(1,this.getScale(sourceWidth, sourceHeight, requestWidth, requestHeight))
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):SampleSizeRounding {
|
||||
return 1
|
||||
}
|
||||
getScale(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let widthPercentage =requestWidth/sourceWidth
|
||||
let heightPercentage =requestHeight/sourceHeight
|
||||
return Math.min(widthPercentage,heightPercentage)
|
||||
}
|
||||
|
||||
}
|
||||
/*不进行下采样*/
|
||||
@Sendable
|
||||
export class DownsampleNone implements BaseDownsampling{
|
||||
getName(){
|
||||
return "DownsampleNone"
|
||||
}
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return 1
|
||||
}
|
||||
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.QUALITY
|
||||
return 1
|
||||
}
|
||||
|
||||
}
|
||||
/* 下采样使得图像的组大尺寸在给定的尺寸的1/2之间*/
|
||||
export class AtMost implements BaseDownsampling{
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth:number,requestHeight: number): number {
|
||||
let maxIntegerFactor=Math.ceil(Math.max(sourceHeight/requestHeight,sourceWidth/requestWidth));
|
||||
let lesserOrEqualSampleSize = Math.max(1,highestOneBit(maxIntegerFactor))
|
||||
let greaterOrEqualSampleSize = lesserOrEqualSampleSize<<(lesserOrEqualSampleSize<maxIntegerFactor?1:0)
|
||||
return 1/greaterOrEqualSampleSize
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.MEMORY
|
||||
}
|
||||
}
|
||||
export class Atleast implements BaseDownsampling{
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let minIntegerFactor=Math.floor(Math.min(sourceHeight/requestHeight,sourceWidth/requestWidth))
|
||||
|
||||
return minIntegerFactor==0?1:1/highestOneBit(minIntegerFactor)
|
||||
}
|
||||
@Sendable
|
||||
export class AtMost implements BaseDownsampling{
|
||||
getName(){
|
||||
return "AtMost"
|
||||
}
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth:number,requestHeight: number): number {
|
||||
let maxIntegerFactor=Math.ceil(Math.max(sourceHeight/requestHeight,sourceWidth/requestWidth));
|
||||
let lesserOrEqualSampleSize = Math.max(1,this.highestOneBit(maxIntegerFactor))
|
||||
let greaterOrEqualSampleSize = lesserOrEqualSampleSize<<(lesserOrEqualSampleSize<maxIntegerFactor?1:0)
|
||||
return 1/greaterOrEqualSampleSize
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.QUALITY
|
||||
}
|
||||
return SampleSizeRounding.MEMORY
|
||||
}
|
||||
highestOneBit(i: number): number {
|
||||
i |= (i >> 1);
|
||||
i |= (i >> 2);
|
||||
i |= (i >> 4);
|
||||
i |= (i >> 8);
|
||||
i |= (i >> 16);
|
||||
return i - (i >>> 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Sendable
|
||||
export class Atleast implements BaseDownsampling{
|
||||
getName(){
|
||||
return "Atleast"
|
||||
}
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let minIntegerFactor=Math.floor(Math.min(sourceHeight/requestHeight,sourceWidth/requestWidth))
|
||||
return minIntegerFactor==0?1:1/this.highestOneBit(minIntegerFactor)
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return 1
|
||||
}
|
||||
highestOneBit(i: number): number {
|
||||
i |= (i >> 1);
|
||||
i |= (i >> 2);
|
||||
i |= (i >> 4);
|
||||
i |= (i >> 8);
|
||||
i |= (i >> 16);
|
||||
return i - (i >>> 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Sendable
|
||||
export class CenterOutside implements BaseDownsampling{
|
||||
static getSampleSizeRounding(orientedSourceWidth: number, orientedSourceHeight: number, targetWidth: number, targetHeight: number): SampleSizeRounding {
|
||||
throw new Error('Method not implemented.')
|
||||
}
|
||||
getName(){
|
||||
return "CenterOutside"
|
||||
}
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let widthPercentage =requestWidth/sourceWidth
|
||||
let heightPercentage =requestHeight/sourceHeight
|
||||
|
@ -55,20 +93,23 @@ export class CenterOutside implements BaseDownsampling{
|
|||
}
|
||||
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.QUALITY
|
||||
return 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Sendable
|
||||
export class FitCenter{
|
||||
public static getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
getName(){
|
||||
return "FitCenter"
|
||||
}
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let widthPercentage =requestWidth/sourceWidth
|
||||
let heightPercentage =requestHeight/sourceHeight
|
||||
return Math.min(widthPercentage,heightPercentage)
|
||||
}
|
||||
public static getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.MEMORY
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return 1
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
/*
|
||||
* asdfasdfasdfasdfasdf*/
|
||||
import { CenterOutside, FitCenter, SampleSizeRounding } from './Downsamplestrategy';
|
||||
import { FileTypeUtil } from '../../utits/Fitetypeutit';
|
||||
import { RequestOption } from '../../Requestoption';
|
||||
import { RequestOption } from '../RequestOption';
|
||||
import { FileTypeUtil } from '../utils/FileTypeUtil';
|
||||
import { CenterOutside, FitCenter, SampleSizeRounding } from './DownsampleStartegy';
|
||||
|
||||
let TAG = 'downsampling'
|
||||
|
||||
export class Downsampler {
|
||||
calculateScaling(
|
||||
imageType: ArrayBuffer,
|
||||
sourceHeight:number,
|
||||
sourceWidth:number,
|
||||
sourceHeight: number,
|
||||
sourceWidth: number,
|
||||
request?: RequestOption
|
||||
):ESObject {
|
||||
): ESObject {
|
||||
const fileType: string | null = new FileTypeUtil().getFileType(imageType)
|
||||
let powerOfTwoWidth: number | null = null;
|
||||
let powerOfTwoHeight: number | null = null;
|
||||
|
@ -26,7 +28,7 @@ export class Downsampler {
|
|||
} else {
|
||||
console.log('宽高都不存在')
|
||||
}
|
||||
if (sourceWidth <= 0 || sourceleight <= 0) return;
|
||||
if (sourceWidth <= 0 || sourceHeight <= 0) return;
|
||||
let orientedSourceWidth = sourceWidth;
|
||||
let orientedSourceHeight = sourceHeight;
|
||||
if (this.isRotationRequired(90)) {
|
||||
|
@ -38,103 +40,112 @@ export class Downsampler {
|
|||
if (exactScaleFactor <= 0) {
|
||||
throw new Error("Cannot round with exactScaleFactor");
|
||||
}
|
||||
console.log('exactScaleFactor', exactScaleFactor)
|
||||
/*安卓的模式*/
|
||||
let rounding: SampleSizeRounding = CenterOutside.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
||||
if (rounding == null) {
|
||||
throw new Error("Cannot round with null rounding");
|
||||
}
|
||||
let outWidth: number = this.round(exactScaleFactor * orientedSourceWidth);
|
||||
let outHeight: number = this.round(exactScaleFactor * orientedSourceHeight);
|
||||
let widthScaleFactor = Math.floor(orientedSourceWidth / outWidth);
|
||||
let heightScaleFactor = Math.floor(orientedSourceHeight / outHeight);
|
||||
let scaleFactor = rounding == SampleSizeRounding.MEMORY ? Math.max(widthScaleFactor, heightScaleFactor) : Math.min(widthScaleFactor, heightScaleFactor)
|
||||
let powerOfTwoSampleSize: number;
|
||||
powerOfTwoSampleSize = Math.max(1, this.highestOneBit(scaleFactor));
|
||||
if (fileType == "JPEG") {
|
||||
let nativeScaling = Hath.min(powerOfTwoSampleSize, 8);
|
||||
powerOfTwoWidth = Math.ceil(orientedSourceWidth / nativeScaling);
|
||||
powerOfTwoHeight = Math.ceil(orientedSourceHeight / nativeScaling);
|
||||
let secondaryScaling = Math.floor(powerOfTwoSampleSize / 8);
|
||||
if (secondaryScaling > 0) {
|
||||
powerOfTwoWidth = powerOfTwoWidth / secondaryScaling;
|
||||
powerOfTwoHeight = powerOfTwoHeight / secondaryScaling;
|
||||
}
|
||||
} else if (fileType == "PNG") {
|
||||
powerOfTwoWidth = Math.floor(orientedSourceWidth / powerOfTwoSampleSize);
|
||||
PowerOfTwoHeight = Math.floor(orientedSourceHeight / powerOfTwoSamplesize);
|
||||
console.log('执行了没', powerOfTwoHeight, powerOfTwoWidth)
|
||||
} else if (fileType == "WEBP") {
|
||||
powerOfTwoWidth = Math.round(orientedSourceWidth / powerOfTwoSampleSize);
|
||||
poWerOfTwoHeight = Math.round(orientedSourceHeight / powerOfTwoSampleSize);
|
||||
} else if (
|
||||
orientedSourceWidth % powerOfTwoSampleSize != 0 || orientedSourceHeight % powerOfTwoSampleSize != 0) {
|
||||
|
||||
|
||||
// let dimensions; number[] = this.getDimensions(imageReader, options, decodeCallbacks,bitmapPool);
|
||||
// powerOfTwoWidth = dimensions[0];
|
||||
// powerofTwoHeight = dimensions[1];
|
||||
} else {
|
||||
powerOfTwoWidth = orientedSourceWidth / 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": power0fTwoWidth, "targetHeight": powerOfTuoHeight }
|
||||
return a
|
||||
console.log('exactScaleFactor', exactScaleFactor)
|
||||
/*安卓的模式*/
|
||||
let rounding: SampleSizeRounding = CenterOutside.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
||||
if (rounding == null) {
|
||||
throw new Error("Cannot round with null rounding");
|
||||
}
|
||||
//decodeStream(imageReader:ImageReader, options: ESObject, callbacks: DecodeCallbacks, bitmapPool: ESObject) {
|
||||
//if (!options.inJustDecodeBounds){
|
||||
// callbacks.onObtainBounds();
|
||||
// imageReader.stopGrowingBuffers();
|
||||
// }
|
||||
let outWidth: number = this.round(exactScaleFactor * orientedSourceWidth);
|
||||
let outHeight: number = this.round(exactScaleFactor * orientedSourceHeight);
|
||||
let widthScaleFactor = Math.floor(orientedSourceWidth / outWidth);
|
||||
let heightScaleFactor = Math.floor(orientedSourceHeight / outHeight);
|
||||
let scaleFactor = rounding == SampleSizeRounding.MEMORY ? Math.max(widthScaleFactor, heightScaleFactor) : Math.min(widthScaleFactor, heightScaleFactor)
|
||||
// 将整型的缩放因子转换为2的次幂采样大小
|
||||
let powerOfTwoSampleSize: number = 0;
|
||||
if (rounding == SampleSizeRounding.MEMORY && powerOfTwoSampleSize < (1 / exactScaleFactor)) {
|
||||
powerOfTwoSampleSize = powerOfTwoSampleSize << 1;
|
||||
}
|
||||
// 基于上一步得出的采样大小,根据不同的图片类型,计算采样后的图片尺寸
|
||||
if (fileType == "JPEG") {
|
||||
let nativeScaling = Math.min(powerOfTwoSampleSize, 8);
|
||||
powerOfTwoWidth = Math.ceil(orientedSourceWidth / nativeScaling);
|
||||
powerOfTwoHeight = Math.ceil(orientedSourceHeight / nativeScaling);
|
||||
let secondaryScaling = Math.floor(powerOfTwoSampleSize / 8);
|
||||
if (secondaryScaling > 0) {
|
||||
powerOfTwoWidth = powerOfTwoWidth / secondaryScaling;
|
||||
powerOfTwoHeight = powerOfTwoHeight / secondaryScaling;
|
||||
}
|
||||
} else if (fileType == "PNG") {
|
||||
powerOfTwoWidth = Math.floor(orientedSourceWidth / powerOfTwoSampleSize);
|
||||
powerOfTwoHeight = Math.floor(orientedSourceHeight / powerOfTwoSampleSize);
|
||||
console.log('执行了没', powerOfTwoHeight, powerOfTwoWidth)
|
||||
} else if (fileType == "WEBP") {
|
||||
powerOfTwoWidth = Math.round(orientedSourceWidth / powerOfTwoSampleSize);
|
||||
powerOfTwoHeight = Math.round(orientedSourceHeight / powerOfTwoSampleSize);
|
||||
} else if (
|
||||
orientedSourceWidth % powerOfTwoSampleSize != 0 || orientedSourceHeight % powerOfTwoSampleSize != 0) {
|
||||
|
||||
|
||||
// let dimensions; number[] = this.getDimensions(imageReader, options, decodeCallbacks,bitmapPool);
|
||||
// powerOfTwoWidth = dimensions[0];
|
||||
// powerofTwoHeight = dimensions[1];
|
||||
} else {
|
||||
powerOfTwoWidth = orientedSourceWidth / 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;
|
||||
// }
|
||||
// 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);
|
||||
//
|
||||
// }
|
||||
|
||||
highest0neBit(i: number): number{
|
||||
i |= (i >> 1);
|
||||
i |= (i >> 2);
|
||||
i |= (i >> 4);
|
||||
i |= (i >> 8);
|
||||
i |= (i >> 16);
|
||||
return i - (i >>> 1);
|
||||
}
|
||||
round(value: number): number {
|
||||
return Math.floor(value +0.5);
|
||||
}
|
||||
isRotationRequired(degreesToRotate: number): boolean {
|
||||
return degreesToRotate == 90 || degreesToRotate == 270;
|
||||
}
|
||||
// isScaling(options: ESObject): boolean {
|
||||
// return options.inTargetDensity >0
|
||||
// && options.inDensity>0
|
||||
// && options.inTargetDensity != options.inDensity;
|
||||
//}
|
||||
getDensityMultiplier(adjustedScaleFactor: number):number{
|
||||
return Math.round(Number.MAX_VALUE * (adjustedScaleFactor <= 1 ? adjustedScaleFactor : 1 / adjustedScaleFactor));
|
||||
}
|
||||
adjustTargetDensityForError(adjustedScaleFactor:number):number{
|
||||
let densityMultiplier = this.getDensityMultiplier(adjustedScaleFactor);
|
||||
let targetDensity = this.round(densityMultiplier * adjustedScaleFactor);
|
||||
let scaleFactorWithError = targetDensity / densityMultiplier;
|
||||
let difference = adjustedScaleFactor / scaleFactorWithError;
|
||||
return this.round(difference * targetDensity);
|
||||
}
|
||||
//}
|
||||
let a: ESObject = { "targetWidth": powerOfTwoWidth, "targetHeight": powerOfTwoHeight }
|
||||
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 {
|
||||
i |= (i >> 1);
|
||||
i |= (i >> 2);
|
||||
i |= (i >> 4);
|
||||
i |= (i >> 8);
|
||||
i |= (i >> 16);
|
||||
return i - (i >>> 1);
|
||||
}
|
||||
|
||||
round(value: number): number {
|
||||
return Math.floor(value + 0.5);
|
||||
}
|
||||
|
||||
isRotationRequired(degreesToRotate: number): boolean {
|
||||
return degreesToRotate == 90 || degreesToRotate == 270;
|
||||
}
|
||||
|
||||
// isScaling(options: ESObject): boolean {
|
||||
// return options.inTargetDensity >0
|
||||
// && options.inDensity>0
|
||||
// && options.inTargetDensity != options.inDensity;
|
||||
//}
|
||||
getDensityMultiplier(adjustedScaleFactor: number): number {
|
||||
return Math.round(Number.MAX_VALUE * (adjustedScaleFactor <= 1 ? adjustedScaleFactor : 1 / adjustedScaleFactor));
|
||||
}
|
||||
|
||||
adjustTargetDensityForError(adjustedScaleFactor: number): number {
|
||||
let densityMultiplier = this.getDensityMultiplier(adjustedScaleFactor);
|
||||
let targetDensity = this.round(densityMultiplier * adjustedScaleFactor);
|
||||
let scaleFactorWithError = targetDensity / densityMultiplier;
|
||||
let difference = adjustedScaleFactor / scaleFactorWithError;
|
||||
return this.round(difference * targetDensity);
|
||||
}
|
||||
}
|
|
@ -563,6 +563,7 @@ export class ImageKnife {
|
|||
data.setDiskMemoryCachePath(this.diskMemoryCache.getPath())
|
||||
data.setPlaceHolderRegisterCacheKey(request.placeholderRegisterCacheKey);
|
||||
data.setPlaceHolderRegisterMemoryCacheKey(request.placeholderRegisterMemoryCacheKey);
|
||||
data.setDownsampType(request.downsampType)
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -809,9 +810,7 @@ async function taskExecute(sendData:SendableData,taskData:TaskParams): Promise<P
|
|||
newRequestOption.thumbSizeMultiplier = sendData.getThumbSizeMultiplier();
|
||||
newRequestOption.thumbDelayTime = sendData.getThumbDelayTime();
|
||||
newRequestOption.size = taskData.size;
|
||||
newRequestOption.placeholderRegisterCacheKey = sendData.getPlaceHolderRegisterCacheKey();
|
||||
newRequestOption.placeholderRegisterMemoryCacheKey = sendData.getPlaceHolderRegisterMemoryCacheKey();
|
||||
|
||||
newRequestOption.downsampType = sendData.getDownsampType();
|
||||
if(taskData.placeholderSrc){
|
||||
newRequestOption.placeholderSrc = taskData.placeholderSrc as string | PixelMap | Resource | undefined;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import { ObjectKey } from './ObjectKey'
|
|||
import common from '@ohos.app.ability.common'
|
||||
import { Priority } from './RequestOption'
|
||||
import { DataFetchResult } from './networkmanage/DataFetchResult'
|
||||
import { BaseDownsampling } from './Downsampling/BaseDownsampling'
|
||||
import { DownsampleNone } from './Downsampling/DownsampleStartegy'
|
||||
|
||||
export interface CropCircleWithBorder{
|
||||
border: number,
|
||||
|
@ -87,6 +89,9 @@ export class ImageKnifeOption {
|
|||
// gif加载展示一帧
|
||||
dontAnimateFlag? = false;
|
||||
|
||||
//下采样
|
||||
downsampling?:BaseDownsampling = new DownsampleNone()
|
||||
|
||||
// 占位图
|
||||
placeholderSrc?: string | PixelMap | Resource;
|
||||
placeholderScaleType?: ScaleType = ScaleType.FIT_CENTER
|
||||
|
|
|
@ -18,6 +18,8 @@ import { collections } from '@kit.ArkTS';
|
|||
import { IDataFetch } from './networkmanage/IDataFetch';
|
||||
import { DiskLruCache } from '../cache/DiskLruCache';
|
||||
import { DownloadClient } from './networkmanage/DownloadClient';
|
||||
import { BaseDownsampling } from './Downsampling/BaseDownsampling';
|
||||
import { DownsampleNone } from './Downsampling/DownsampleStartegy';
|
||||
|
||||
@Sendable
|
||||
export class SendableData{
|
||||
|
@ -39,9 +41,7 @@ export class SendableData{
|
|||
private diskMemoryCachePath: string = '';
|
||||
private diskMemoryCache?: DiskLruCache;
|
||||
private dataFetch: IDataFetch = new DownloadClient();
|
||||
private placeholderRegisterCacheKey: string = "";
|
||||
private placeholderRegisterMemoryCacheKey: string = "";
|
||||
|
||||
private downsampType: BaseDownsampling = new DownsampleNone();
|
||||
public setDataFetch(value: IDataFetch) {
|
||||
this.dataFetch = value;
|
||||
}
|
||||
|
@ -179,19 +179,11 @@ export class SendableData{
|
|||
return this.usageType;
|
||||
}
|
||||
|
||||
public setPlaceHolderRegisterCacheKey(value: string) {
|
||||
this.placeholderRegisterCacheKey = value;
|
||||
public setDownsampType(Type: BaseDownsampling): BaseDownsampling{
|
||||
return this.downsampType = Type;
|
||||
}
|
||||
|
||||
public getPlaceHolderRegisterCacheKey(): string {
|
||||
return this.placeholderRegisterCacheKey;
|
||||
}
|
||||
|
||||
public setPlaceHolderRegisterMemoryCacheKey(value: string) {
|
||||
this.placeholderRegisterMemoryCacheKey = value;
|
||||
}
|
||||
|
||||
public getPlaceHolderRegisterMemoryCacheKey(): string {
|
||||
return this.placeholderRegisterMemoryCacheKey;
|
||||
public getDownsampType(): BaseDownsampling {
|
||||
return this.downsampType;
|
||||
}
|
||||
}
|
|
@ -34,7 +34,6 @@ import { LogUtil } from '../../imageknife/utils/LogUtil'
|
|||
import { BusinessError } from '@ohos.base'
|
||||
import { DataFetchResult } from '../networkmanage/DataFetchResult'
|
||||
|
||||
|
||||
export enum Stage {
|
||||
|
||||
INITIALIZE,
|
||||
|
@ -167,7 +166,7 @@ export class RequestManager {
|
|||
// gif、webp处理
|
||||
if ((ImageKnifeData.GIF == typeValue || ImageKnifeData.WEBP == typeValue) && !request.dontAnimateFlag) {
|
||||
// 处理gif、webp
|
||||
this.gifProcess(onComplete, onError, arrayBuffer, typeValue)
|
||||
this.gifProcess(onComplete, onError, arrayBuffer, typeValue,request)
|
||||
} else if (ImageKnifeData.SVG == typeValue) {
|
||||
// 处理svg
|
||||
this.svgProcess(request, onComplete, onError, arrayBuffer, typeValue)
|
||||
|
@ -331,13 +330,13 @@ export class RequestManager {
|
|||
let success = (value: PixelMap) => {
|
||||
onComplete(value);
|
||||
}
|
||||
this.mParseImageUtil.parseImage(source, success, onError)
|
||||
this.mParseImageUtil.parseImage(source, success, onError, request)
|
||||
}, this.options.thumbDelayTime)
|
||||
} else {
|
||||
let success = (value: PixelMap) => {
|
||||
onComplete(value);
|
||||
}
|
||||
this.mParseImageUtil.parseImage(source, success, onError)
|
||||
this.mParseImageUtil.parseImage(source, success, onError, request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,13 +359,13 @@ export class RequestManager {
|
|||
let success = (value: PixelMap) => {
|
||||
onComplete(value);
|
||||
}
|
||||
this.mParseImageUtil.parseImage(source, success, onError)
|
||||
this.mParseImageUtil.parseImage(source, success, onError, request)
|
||||
}, this.options.thumbDelayTime)
|
||||
} else {
|
||||
let success = (value: PixelMap) => {
|
||||
onComplete(value);
|
||||
}
|
||||
this.mParseImageUtil.parseImage(source, success, onError)
|
||||
this.mParseImageUtil.parseImage(source, success, onError, request)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,7 +453,7 @@ export class RequestManager {
|
|||
this.saveCacheAndDisk(value, filetype, onComplete, source);
|
||||
}
|
||||
}
|
||||
this.mParseImageUtil.parseImage(source, success, onError)
|
||||
this.mParseImageUtil.parseImage(source, success, onError, request)
|
||||
}, this.options.thumbDelayTime)
|
||||
} else {
|
||||
let success = (value: PixelMap) => {
|
||||
|
@ -462,7 +461,7 @@ export class RequestManager {
|
|||
this.saveCacheAndDisk(value, filetype, onComplete, source);
|
||||
}
|
||||
}
|
||||
this.mParseImageUtil.parseImage(source, success, onError)
|
||||
this.mParseImageUtil.parseImage(source, success, onError, request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -534,9 +533,17 @@ export class RequestManager {
|
|||
svgParseImpl.parseSvg(option, arraybuffer, onComplete, onError)
|
||||
}
|
||||
|
||||
private gifProcess(onComplete: (value: PixelMap | GIFFrame[]) => void | PromiseLike<ImageKnifeData>, onError: (reason?: BusinessError | string) => void, arraybuffer: ArrayBuffer, typeValue: string, cacheStrategy?: (cacheData: ImageKnifeData) => void) {
|
||||
private gifProcess(
|
||||
onComplete: (value: PixelMap | GIFFrame[]) => void | PromiseLike<ImageKnifeData>,
|
||||
onError: (reason?: BusinessError | string) => void,
|
||||
arraybuffer: ArrayBuffer,
|
||||
typeValue: string,
|
||||
request?:RequestOption,
|
||||
cacheStrategy?: (cacheData: ImageKnifeData) => void
|
||||
) {
|
||||
let gifParseImpl = new GIFParseImpl()
|
||||
gifParseImpl.parseGifs(arraybuffer, (data?: GIFFrame[], err?: BusinessError | string) => {
|
||||
gifParseImpl.parseGifs(
|
||||
arraybuffer, (data?: GIFFrame[], err?: BusinessError | string) => {
|
||||
if (err) {
|
||||
onError(err)
|
||||
}
|
||||
|
@ -552,6 +559,6 @@ export class RequestManager {
|
|||
} else {
|
||||
onError('Parse GIF callback data is null, you need check callback data!')
|
||||
}
|
||||
})
|
||||
},request)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,15 @@ import { IParseImage } from '../interface/IParseImage'
|
|||
import image from '@ohos.multimedia.image';
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import { RequestOption } from '../RequestOption';
|
||||
import { Downsampler } from '../Downsampling/Downsampler';
|
||||
|
||||
export class ParseImageUtil implements IParseImage<PixelMap> {
|
||||
parseImage(imageinfo: ArrayBuffer, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>, onErrorFunction: (reason?: BusinessError | string) => void,request?:RequestOption) {
|
||||
parseImage(
|
||||
imageinfo: ArrayBuffer,
|
||||
onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>,
|
||||
onErrorFunction: (reason?: BusinessError | string) => void,
|
||||
request?:RequestOption
|
||||
) {
|
||||
this.parseImageThumbnail(1, imageinfo, onCompleteFunction, onErrorFunction,request)
|
||||
}
|
||||
|
||||
|
@ -37,14 +43,17 @@ export class ParseImageUtil implements IParseImage<PixelMap> {
|
|||
editable: true,
|
||||
desiredSize: defaultSize
|
||||
};
|
||||
const b = new Downsamper(imageinfo, hValue, wValue, requ,request)
|
||||
let options: image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
height: b.targetHeight,
|
||||
width: b.targetWidth
|
||||
}
|
||||
};
|
||||
if(request?.downsampType.getName()!=='DownsampleNone'){
|
||||
const b:ESObject = new Downsampler().calculateScaling(imageinfo, hValue, wValue,request)
|
||||
opts= {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
height: b.targetHeight,
|
||||
width: b.targetWidth
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
|
||||
|
|
|
@ -34,7 +34,11 @@ export interface gifBackData {
|
|||
}
|
||||
|
||||
export class GIFParseImpl implements IParseGif {
|
||||
parseGifs(imageinfo: ArrayBuffer, callback: (data?: GIFFrame[], err?: BusinessError | string) => void) {
|
||||
parseGifs(
|
||||
imageinfo: ArrayBuffer,
|
||||
callback: (data?: GIFFrame[], err?: BusinessError | string) => void,
|
||||
_request?: RequestOption
|
||||
) {
|
||||
// 硬解码流程
|
||||
let imageSource = image.createImageSource(imageinfo);
|
||||
let decodeOpts: image.DecodingOptions = {
|
||||
|
@ -42,7 +46,29 @@ export class GIFParseImpl implements IParseGif {
|
|||
editable: true,
|
||||
rotate: 0
|
||||
}
|
||||
let data:GIFFrame[] = [];
|
||||
let hValue: number = 0
|
||||
let wValue: number = 0
|
||||
imageSource.getImageInfo().then((value) => {
|
||||
hValue = Math.round(value.size, height);
|
||||
wValue = Math.round(value.size, height);
|
||||
console.log('原始宽高:', JSON.stringify(value.size))
|
||||
console.log('classType', JSON.stringify(_request?.downsampType.getName()))
|
||||
console.log('classType2', hValue, wValue)
|
||||
if (_request?.downsampType.getName() !== 'DownsampleNone') {
|
||||
const b: ESObject = new Downsampler().calculateScaling(imageinfo, Math.round(value.size.height), Math.round(value.size.width), _request)
|
||||
console.log("classType1", JSON.stringify(b))
|
||||
decodeOpts = {
|
||||
sampleSize: 1,
|
||||
editable: true,
|
||||
rotate: 0,
|
||||
desiredSize: {
|
||||
width: b.targetWidth,
|
||||
height: b.targetHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
let data: GIFFrame[] = [];
|
||||
imageSource.createPixelMapList(decodeOpts).then((pixelList: Array<PixelMap>) => {
|
||||
//sdk的api接口发生变更:从.getDelayTime() 变为.getDelayTimeList()
|
||||
imageSource.getDelayTimeList().then(delayTimes => {
|
||||
|
@ -60,20 +86,20 @@ export class GIFParseImpl implements IParseGif {
|
|||
}
|
||||
data.push(frame)
|
||||
}
|
||||
callback(data,undefined)
|
||||
callback(data, undefined)
|
||||
imageSource.release();
|
||||
}).catch((err: string) => {
|
||||
imageSource.release();
|
||||
callback(undefined,err)
|
||||
callback(undefined, err)
|
||||
})
|
||||
}
|
||||
}).catch((err: string) => {
|
||||
imageSource.release();
|
||||
callback(undefined,err)
|
||||
callback(undefined, err)
|
||||
})
|
||||
}).catch((err: string) => {
|
||||
imageSource.release();
|
||||
callback(undefined,err)
|
||||
callback(undefined, err)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -17,5 +17,9 @@ import { GIFFrame } from './GIFFrame'
|
|||
import worker from '@ohos.worker';
|
||||
export interface IParseGif{
|
||||
// gif解析
|
||||
parseGifs:(imageinfo: ArrayBuffer, callback: (data?:GIFFrame[], err?:BusinessError|string) => void, worker?:worker.ThreadWorker,runMainThread?:boolean)=>void
|
||||
parseGifs:(
|
||||
imageinfo: ArrayBuffer,
|
||||
callback: (data?:GIFFrame[], err?:BusinessError|string) => void,
|
||||
request:ESObject,
|
||||
worker?:worker.ThreadWorker,runMainThread?:boolean)=>void
|
||||
}
|
|
@ -17,6 +17,7 @@ import { RequestOption } from '../../RequestOption'
|
|||
import { BusinessError } from '@ohos.base'
|
||||
import { ImageKnifeData, ImageKnifeType } from '../../ImageKnifeData'
|
||||
import image from '@ohos.multimedia.image'
|
||||
import { Downsampler } from '../../Downsampling/Downsampler'
|
||||
|
||||
export class SVGParseImpl implements IParseSvg {
|
||||
parseSvg(option: RequestOption, imageInfo: ArrayBuffer,
|
||||
|
@ -24,16 +25,29 @@ export class SVGParseImpl implements IParseSvg {
|
|||
onErrorFunction: (reason?: BusinessError | string) => void) {
|
||||
|
||||
let imageSource: image.ImageSource = image.createImageSource(imageInfo); // 步骤一:文件转为pixelMap 然后变换 给Image组件
|
||||
let hValue = Math.round(option.size.height);
|
||||
let wValue = Math.round(option.size.width);
|
||||
let defaultSize: image.Size = {
|
||||
height: hValue,
|
||||
width: wValue
|
||||
};
|
||||
let opts: image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: defaultSize
|
||||
};
|
||||
imageSource.getImageInfo().then((value) => {
|
||||
let hValue = Math.round(value.size.height);
|
||||
let wValue = Math.round(value.size.width);
|
||||
let defaultSize: image.Size = {
|
||||
height: hValue,
|
||||
width: wValue
|
||||
};
|
||||
let opts: image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: defaultSize
|
||||
};
|
||||
if (option?.downsampType.getName() !== 'DownsampleNone') {
|
||||
const b: ESObject = new Downsampler().calculateScaling(imageInfo, hValue, wValue, option)
|
||||
console.log("bbb-----", JSON.stringify(b))
|
||||
opts = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: b.targetWidth,
|
||||
height: b.targetHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, pixelMap)
|
||||
onComplete(imageKnifeData?.drawPixelMap?.imagePixelMap as PixelMap);
|
||||
|
|
Loading…
Reference in New Issue