diff --git a/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets b/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets index 45d3300..ee6521b 100644 --- a/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import { EngineKeyFactories, EngineKeyInterface, RequestOption } from '@ohos/imageknife' -import { ObjectKey } from '@ohos/imageknife/src/main/ets/components/imageknife/ObjectKey'; +import { ObjectKey } from '@ohos/imageknife'; export class CustomEngineKeyImpl implements EngineKeyInterface { redefineUrl: (loadSrc: string) => string; diff --git a/entry/src/main/ets/pages/basicTestResourceManagerPage.ets b/entry/src/main/ets/pages/basicTestResourceManagerPage.ets index edc59e8..824b00c 100644 --- a/entry/src/main/ets/pages/basicTestResourceManagerPage.ets +++ b/entry/src/main/ets/pages/basicTestResourceManagerPage.ets @@ -41,7 +41,9 @@ struct BasicTestResourceManagerPage { let arrayBuffer = this.typedArrayToBuffer(data); let filetypeUtil = new FileTypeUtil(); let fileType = filetypeUtil.getFileType(arrayBuffer); - this.fileTypeStr = fileType; + if(fileType != null) { + this.fileTypeStr = fileType; + } }) .catch((err:BusinessError) => { console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err)); @@ -63,7 +65,9 @@ struct BasicTestResourceManagerPage { .decode(data); let filetypeUtil = new FileTypeUtil(); let fileType = filetypeUtil.getFileType(arrayBuffer); - this.fileTypeStr = fileType; + if(fileType != null) { + this.fileTypeStr = fileType; + } }) .catch((err:BusinessError) => { console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err)); diff --git a/entry/src/main/ets/pages/pngjTestCasePage.ets b/entry/src/main/ets/pages/pngjTestCasePage.ets index 390ddae..15ec0fe 100644 --- a/entry/src/main/ets/pages/pngjTestCasePage.ets +++ b/entry/src/main/ets/pages/pngjTestCasePage.ets @@ -120,7 +120,8 @@ struct PngjTestCasePage { name: 'readPngImageAsync' }) pngj.readPngImageAsync(png_worker, this.pngSource2!, {pngCallback: (sender:ArrayBuffer, value:Record) => { - this.pngSource1 = sender + this.pngSource2 = sender + this.hint8 = '重新获取buffer才能测试' this.hint2 = 'img with=' + value.width + ' img height=' + value.height + ' img depth=' + value.depth + ' img ctype=' + value.ctype this.pngdecodeRun2 = false; diff --git a/entry/src/main/ets/pages/transformPixelMapPage.ets b/entry/src/main/ets/pages/transformPixelMapPage.ets index e9cabbb..226b8ed 100644 --- a/entry/src/main/ets/pages/transformPixelMapPage.ets +++ b/entry/src/main/ets/pages/transformPixelMapPage.ets @@ -17,7 +17,7 @@ import { CropCircleTransformation } from '@ohos/imageknife' import { RoundedCornersTransformation } from '@ohos/imageknife' import { CropCircleWithBorderTransformation -} from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation' +} from '@ohos/imageknife' import { RotateImageTransformation } from '@ohos/imageknife' import { CropSquareTransformation } from '@ohos/imageknife' import { CropTransformation } from '@ohos/imageknife' diff --git a/imageknife/index.ets b/imageknife/index.ets index 739c6ca..1dbd5ef 100644 --- a/imageknife/index.ets +++ b/imageknife/index.ets @@ -95,6 +95,7 @@ export { UPNG } from './src/main/ets/components/3rd_party/upng/UPNG' */ export { ImageKnife } from './src/main/ets/components/imageknife/ImageKnife' export { ImageKnifeGlobal } from './src/main/ets/components/imageknife/ImageKnifeGlobal' +export { ObjectKey } from './src/main/ets/components/imageknife/ObjectKey' export {RequestOption,Size} from './src/main/ets/components/imageknife/RequestOption' export { ImageKnifeComponent, ScaleType, ScaleTypeHelper } from './src/main/ets/components/imageknife/ImageKnifeComponent' export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory' diff --git a/imageknife/src/main/ets/components/cache/MemoryLruCache.ets b/imageknife/src/main/ets/components/cache/MemoryLruCache.ets new file mode 100644 index 0000000..d3f4f13 --- /dev/null +++ b/imageknife/src/main/ets/components/cache/MemoryLruCache.ets @@ -0,0 +1,31 @@ +import { ImageKnife } from '../imageknife/ImageKnife'; +import { ImageKnifeData } from '../imageknife/ImageKnifeData'; +import { LruCache } from './LruCache'; + +export class MemoryLruCache extends LruCache{ + constructor(maxsize:number) { + super(maxsize) + } + + // 移除较少使用的缓存数据 + trimToSize(tempsize: number) { + while (true) { + if (tempsize < 0) { + this.map.clear() + this.size = 0 + break + } + if (this.size <= tempsize || this.map.isEmpty()) { + break + } + let delkey = this.map.getFirstKey() + let data : ImageKnifeData|undefined = this.map.get(delkey) + if(data != undefined){ + data.release() + } + this.map.remove(delkey) + this.size-- + } + } + +} \ No newline at end of file diff --git a/imageknife/src/main/ets/components/cache/key/EngineKeyInterface.ets b/imageknife/src/main/ets/components/cache/key/EngineKeyInterface.ets index 637b4d2..90985a0 100644 --- a/imageknife/src/main/ets/components/cache/key/EngineKeyInterface.ets +++ b/imageknife/src/main/ets/components/cache/key/EngineKeyInterface.ets @@ -17,11 +17,11 @@ import { RequestOption } from '../../imageknife/RequestOption' export interface EngineKeyInterface { // 生成内存缓存 - generateMemoryCacheKey(loadSrc: string, size: string, transformed: string, dontAnimate: boolean, signature: ObjectKey): string + generateMemoryCacheKey(loadSrc: string, size: string, transformed: string, dontAnimate: boolean, signature: ObjectKey | undefined): string // 生成原图变换后的图片的磁盘缓存 - generateTransformedDiskCacheKey(loadSrc: string, size: string, transformed: string, dontAnimate: boolean, signature: ObjectKey): string + generateTransformedDiskCacheKey(loadSrc: string, size: string, transformed: string, dontAnimate: boolean, signature: ObjectKey | undefined): string // 生成原图的磁盘缓存 - generateOriginalDiskCacheKey(loadSrc: string, signature: ObjectKey): string + generateOriginalDiskCacheKey(loadSrc: string, signature: ObjectKey | undefined): string } diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets index 85ed51a..e28c7a3 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets @@ -14,7 +14,6 @@ */ import { DiskLruCache } from "@ohos/disklrucache" -import { LruCache } from "../cache/LruCache" import { EngineKeyFactories } from "../cache/key/EngineKeyFactories" import { EngineKeyInterface } from "../cache/key/EngineKeyInterface" import { RequestOption } from "../imageknife/RequestOption" @@ -41,10 +40,11 @@ import worker from '@ohos.worker' import common from '@ohos.app.ability.common' import HashMap from '@ohos.util.HashMap' import LinkedList from '@ohos.util.LinkedList' +import { MemoryLruCache } from '../cache/MemoryLruCache' export class ImageKnife { static readonly SEPARATOR: string = '/' - memoryCache: LruCache; + memoryCache: MemoryLruCache; diskMemoryCache: DiskLruCache; dataFetch: IDataFetch; resourceFetch: IResourceFetch; @@ -78,7 +78,7 @@ export class ImageKnife { this.pausedMaps = new EasyLinkedHashMap(); // 构造方法传入size 为保存文件个数 - this.memoryCache = new LruCache(100); + this.memoryCache = new MemoryLruCache(100); // 创建disk缓存 传入的size 为多少比特 比如20KB 传入20*1024 this.diskMemoryCache = DiskLruCache.create(ImageKnifeGlobal.getInstance().getHapContext()); @@ -100,7 +100,7 @@ export class ImageKnife { } - getMemoryCache(): LruCache { + getMemoryCache(): MemoryLruCache { return this.memoryCache; } @@ -136,7 +136,7 @@ export class ImageKnife { return ImageKnifeGlobal.getInstance().getHapContext(); } - setMemoryCache(lrucache: LruCache) { + setMemoryCache(lrucache: MemoryLruCache) { this.memoryCache = lrucache; } @@ -177,9 +177,9 @@ export class ImageKnife { // 替代原来的LruCache public replaceLruCache(size: number) { if (this.memoryCache.map.size() <= 0) { - this.memoryCache = new LruCache(size); + this.memoryCache = new MemoryLruCache(size); } else { - let newLruCache = new LruCache(size); + let newLruCache = new MemoryLruCache(size); this.memoryCache.foreachLruCache((value: ImageKnifeData, key: string, map: Object) => { newLruCache.put(key, value); }) @@ -331,7 +331,7 @@ export class ImageKnife { let signature = request.signature; - if (signature) { + if (signature != undefined) { console.log("唯一标识:" + signature.getKey()) } @@ -421,7 +421,9 @@ export class ImageKnife { } if (hasEqualRunning) { - this.keyEqualPendingToRun(tailNode.value); + if(tailNode.value != null) { + this.keyEqualPendingToRun(tailNode.value); + } } else { this.searchNextKeyToRun(); } diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index 6516eb9..f8c554a 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -82,7 +82,7 @@ export struct ImageKnifeComponent { private onReadyNext?: (data:ImageKnifeData|number|undefined) => void = undefined private onReadyNextData:ImageKnifeData|number|undefined = undefined - private detachFromLayout:DetachFromLayout; + private detachFromLayout:DetachFromLayout|undefined = undefined; build() { Canvas(this.context) @@ -587,7 +587,7 @@ export struct ImageKnifeComponent { aboutToDisappear() { LogUtil.log('ImageKnifeComponent aboutToDisappear happened!') - if(this.detachFromLayout){ + if(this.detachFromLayout != undefined){ this.detachFromLayout.detach(); } diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeData.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeData.ets index d291b67..2179d11 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeData.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeData.ets @@ -84,4 +84,45 @@ export class ImageKnifeData { isResource(): boolean { return ImageKnifeType.RESOURCE == this.imageKnifeType; } + + release(){ + if(this.isPixelMap()){ + if(this.drawPixelMap != undefined && this.drawPixelMap.imagePixelMap != undefined){ + this.drawPixelMap.imagePixelMap.release() + .then(()=>{ + if(this.drawPixelMap != undefined && this.drawPixelMap.imagePixelMap !=undefined){ + this.drawPixelMap.imagePixelMap = undefined; + } + }) + } + } + if(this.isGIFFrame()){ + if(this.drawGIFFrame != undefined){ + let gifFrames = this.drawGIFFrame.imageGIFFrames; + if(gifFrames != undefined){ + for (let i = 0; i < gifFrames.length; i++) { + let tempFrame = gifFrames[i]; + if(tempFrame.drawPixelMap != undefined){ + tempFrame.drawPixelMap.release() + } + } + this.drawGIFFrame.imageGIFFrames = undefined + } + } + } + + if(this.isString()){ + if(this.drawString != undefined && this.drawString.imageString!=undefined){ + this.drawString.imageString = undefined + } + } + + if(this.isResource()){ + if(this.drawResource != undefined && this.drawResource.imageResource != undefined){ + this.drawResource.imageResource = undefined + } + } + + } + } \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/RequestOption.ets b/imageknife/src/main/ets/components/imageknife/RequestOption.ets index 5daad2b..cd25be0 100644 --- a/imageknife/src/main/ets/components/imageknife/RequestOption.ets +++ b/imageknife/src/main/ets/components/imageknife/RequestOption.ets @@ -140,7 +140,7 @@ export class RequestOption { generateUUID(): string { let d = new Date().getTime(); - const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( new RegExp("[xy]","g"), (c) => { const r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); diff --git a/imageknife/src/main/ets/components/imageknife/compress/Engine.ets b/imageknife/src/main/ets/components/imageknife/compress/Engine.ets index 2a70970..5c2aa3a 100644 --- a/imageknife/src/main/ets/components/imageknife/compress/Engine.ets +++ b/imageknife/src/main/ets/components/imageknife/compress/Engine.ets @@ -98,10 +98,11 @@ export class Engine { } imageResource.createPixelMap(options) .then(bitmap => { - + imageResource.release() }) .catch((error: BusinessError) => { this.mCompressListener.onError("ptah createPixelMap fail,because error:" + JSON.stringify(error as BusinessError)) + imageResource.release() }) @@ -173,11 +174,13 @@ export class Engine { if (this.mCompressListener) { this.mCompressListener.onSuccess(bitmap, path); } + imageRes.release() }) .catch((error:BusinessError) => { if (this.mCompressListener) { this.mCompressListener.onError("buffer generated pixelMap fail,because error:" + JSON.stringify(error as BusinessError)) } + imageRes.release() }) } diff --git a/imageknife/src/main/ets/components/imageknife/compress/provider/RecourseProvider.ets b/imageknife/src/main/ets/components/imageknife/compress/provider/RecourseProvider.ets index f1eadc2..9746c92 100644 --- a/imageknife/src/main/ets/components/imageknife/compress/provider/RecourseProvider.ets +++ b/imageknife/src/main/ets/components/imageknife/compress/provider/RecourseProvider.ets @@ -51,7 +51,10 @@ export class RecourseProvider extends CompressAdapter { .then(data => { let buffer = this.uint8ArrayToBuffer(data); let fileTypeUtil = new FileTypeUtil() - this._mPixelMapHeader = fileTypeUtil.getFileType(buffer); + let fileType = fileTypeUtil.getFileType(buffer); + if(fileType != null) { + this._mPixelMapHeader = fileTypeUtil.getFileType(buffer); + } callback.compressDataListener(buffer); }) .catch((err: BusinessError) => { diff --git a/imageknife/src/main/ets/components/imageknife/crop/Crop.ets b/imageknife/src/main/ets/components/imageknife/crop/Crop.ets index fa087f5..da7ded7 100644 --- a/imageknife/src/main/ets/components/imageknife/crop/Crop.ets +++ b/imageknife/src/main/ets/components/imageknife/crop/Crop.ets @@ -66,9 +66,11 @@ export namespace Crop { } else { func?.cropCallback("", data); } + imageSource.release() }) .catch((e:BusinessError) => { func?.cropCallback(e, null); + imageSource.release() }) } } diff --git a/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets b/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets index d01c282..a319dac 100644 --- a/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets +++ b/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets @@ -893,6 +893,7 @@ export class Options { if (readyCrop) { readyCrop(); } + imageSource.release() }) }); diff --git a/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets b/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets index 527d447..9732a7b 100644 --- a/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets +++ b/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets @@ -53,23 +53,28 @@ export class ErrorHolderManager { if (typeof res.id != 'undefined' && typeof res.id != 'undefined') { let resourceFetch = new ParseResClient(); let suc = (arraybuffer:ArrayBuffer) => { - let fileTypeUtil:FileTypeUtil = new FileTypeUtil(); - let typeValue:string = fileTypeUtil.getFileType(arraybuffer); - switch (typeValue) { - case SupportFormat.svg: - this.svgProcess(onComplete, onError, arraybuffer, typeValue) - break; - case SupportFormat.jpg: - case SupportFormat.png: - case SupportFormat.bmp: - case SupportFormat.gif: - case SupportFormat.tiff: - case SupportFormat.webp: - this.mediaImageProcess(onComplete, onError, arraybuffer, typeValue) - break; - default: - onError("ErrorHolderManager 文件类型不支持") - break; + let fileTypeUtil: FileTypeUtil = new FileTypeUtil(); + + let typeValue: string | null = fileTypeUtil.getFileType(arraybuffer); + if (typeValue != null) { + switch (typeValue) { + case SupportFormat.svg: + this.svgProcess(onComplete, onError, arraybuffer, typeValue) + break; + case SupportFormat.jpg: + case SupportFormat.png: + case SupportFormat.bmp: + case SupportFormat.gif: + case SupportFormat.tiff: + case SupportFormat.webp: + this.mediaImageProcess(onComplete, onError, arraybuffer, typeValue) + break; + default: + onError("ErrorHolderManager 文件类型不支持") + break; + } + }else{ + onError("ErrorHolderManager 文件类型为null,请检查数据源arraybuffer") } } resourceFetch.loadResource(res, suc, onError) diff --git a/imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets b/imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets index 0551f72..e956d14 100644 --- a/imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets +++ b/imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets @@ -33,7 +33,7 @@ export class HttpDownloadClient implements IDataFetch { loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) { try { let httpRequest = http.createHttp() - let arrayBuffers = new Array(); + let arrayBuffers = new Array(); httpRequest.on('headersReceive', (header: Object) => { // 跟服务器连接成功准备下载 if (request.progressFunc) { @@ -73,12 +73,7 @@ export class HttpDownloadClient implements IDataFetch { if (!err && data == 200) { } else { - httpRequest.off('headersReceive'); - httpRequest.off('dataReceive'); - httpRequest.off('dataReceiveProgress'); - httpRequest.off('dataEnd'); - httpRequest.destroy() - onError('HttpDownloadClient err message =' + err.message) + onError(`HttpDownloadClient has error, http code = ${data}`) } } ) diff --git a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets index 33b41d5..a7615ba 100644 --- a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets +++ b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets @@ -433,7 +433,12 @@ export class RequestManager { // 步骤二: 文件名保存一份全局 // 步骤三:查看文件是否支持 非支持类型直接返回 let fileTypeUtil = new FileTypeUtil(); - let filetype = fileTypeUtil.getFileType(source); + let filetype:string|null = fileTypeUtil.getFileType(source); + if(filetype == null){ + onError("下载文件解析后类型为null,请检查数据源!"); + return; + } + if (!fileTypeUtil.isImage(source)) { onError("暂不支持 下载文件类型!类型=" + filetype); return; @@ -473,11 +478,15 @@ export class RequestManager { if (this.options.transformations[0]) { // thumbnail 缩略图部分 if (this.options.thumbSizeMultiplier) { - this.thumbnailProcess(source, filetype, onComplete, onError); + if(filetype != null) { + this.thumbnailProcess(source, filetype, onComplete, onError); + } } else { this.options.transformations[0].transform(source, this.options, {asyncTransform: (error:BusinessError|string, pixelMap: PixelMap|null) => { if (pixelMap) { - this.saveCacheAndDisk(pixelMap, filetype, onComplete, source); + if(filetype != null) { + this.saveCacheAndDisk(pixelMap, filetype, onComplete, source); + } } else { onError(error); } @@ -495,13 +504,17 @@ export class RequestManager { this.mParseImageUtil.parseImageThumbnail(this.options.thumbSizeMultiplier, source, thumbSuccess, thumbError); setTimeout(() => { let success = (value: PixelMap) => { - this.saveCacheAndDisk(value, filetype, onComplete, source); + if(filetype != null) { + this.saveCacheAndDisk(value, filetype, onComplete, source); + } } this.mParseImageUtil.parseImage(source, success, onError) }, this.options.thumbDelayTime) } else { let success = (value: PixelMap) => { - this.saveCacheAndDisk(value, filetype, onComplete, source); + if(filetype != null) { + this.saveCacheAndDisk(value, filetype, onComplete, source); + } } this.mParseImageUtil.parseImage(source, success, onError) } diff --git a/imageknife/src/main/ets/components/imageknife/transform/BlurTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/BlurTransformation.ets index b309333..a8c3099 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/BlurTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/BlurTransformation.ets @@ -74,11 +74,13 @@ export class BlurTransformation implements BaseTransform { } else { fastBlur.blur(data, this._mRadius, true, func); } + imageSource.release() }) .catch((e:BusinessError) => { LogUtil.log(Constants.PROJECT_TAG + ";error:" + e); + imageSource.release() func?.asyncTransform(e, null); - }) + }) }}) } } \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/transform/BrightnessFilterTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/BrightnessFilterTransformation.ets index a333210..a63feb8 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/BrightnessFilterTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/BrightnessFilterTransformation.ets @@ -76,7 +76,7 @@ export class BrightnessFilterTransformation implements BaseTransform { } } let data = await imageSource.createPixelMap(options); - + imageSource.release() let bufferData = new ArrayBuffer(data.getPixelBytesNumber()); await data.readPixelsToBuffer(bufferData); diff --git a/imageknife/src/main/ets/components/imageknife/transform/ContrastFilterTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/ContrastFilterTransformation.ets index 11d9946..f45a369 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/ContrastFilterTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/ContrastFilterTransformation.ets @@ -89,7 +89,7 @@ export class ContrastFilterTransformation implements BaseTransform { } let data = await imageSource.createPixelMap(options); - + imageSource.release() let bufferData = new ArrayBuffer(data.getPixelBytesNumber()); await data.readPixelsToBuffer(bufferData); diff --git a/imageknife/src/main/ets/components/imageknife/transform/CropCircleTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/CropCircleTransformation.ets index 239810d..f84be78 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/CropCircleTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/CropCircleTransformation.ets @@ -75,12 +75,14 @@ export class CropCircleTransformation implements BaseTransform { imageSource.createPixelMap(options) .then((p:PixelMap) => { this.transformCircle(p, func); + imageSource.release() }) .catch((e:BusinessError) => { LogUtil.log(Constants.PROJECT_TAG + CropCircleTransformation.TAG + " transform e:" + e); if (func!=undefined) { func?.asyncTransform(Constants.PROJECT_TAG + CropCircleTransformation.TAG + "e" + e, null); } + imageSource.release() }) } diff --git a/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation.ets index 183c47e..8972c84 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation.ets @@ -93,12 +93,14 @@ export class CropCircleWithBorderTransformation implements BaseTransform { this.transformPixelMap(pixelMap, outWith, outHeight, func); + imageSource.release() }) .catch((e:BusinessError) => { LogUtil.log(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e); if (func!=undefined) { func?.asyncTransform(Constants.PROJECT_TAG + ";CropCircleWithBorderTransformation e:" + e, null); } + imageSource.release() }) } diff --git a/imageknife/src/main/ets/components/imageknife/transform/CropSquareTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/CropSquareTransformation.ets index 05b33aa..ca84913 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/CropSquareTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/CropSquareTransformation.ets @@ -73,11 +73,13 @@ export class CropSquareTransformation implements BaseTransform { if (func != undefined) { func?.asyncTransform("", data); } + imageSource.release() }) .catch((e:BusinessError) => { if (func != undefined) { func?.asyncTransform(Constants.PROJECT_TAG + ";CropSquareTransformation e:" + e, null); } + imageSource.release() }) }) .catch((error:BusinessError) => { diff --git a/imageknife/src/main/ets/components/imageknife/transform/CropTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/CropTransformation.ets index d98f56f..416af67 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/CropTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/CropTransformation.ets @@ -83,9 +83,11 @@ export class CropTransformation implements BaseTransform { imageSource.createPixelMap(options) .then((data:PixelMap) => { func?.asyncTransform("", data); + imageSource.release() }) .catch((e:BusinessError) => { LogUtil.log(Constants.PROJECT_TAG + ";error:" + e); + imageSource.release() func?.asyncTransform(e, null); }) }}) diff --git a/imageknife/src/main/ets/components/imageknife/transform/GrayscaleTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/GrayscaleTransformation.ets index fc23f74..fb4ca87 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/GrayscaleTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/GrayscaleTransformation.ets @@ -68,7 +68,7 @@ export class GrayscaleTransformation implements BaseTransform { } } let data:PixelMap= await imageSource.createPixelMap(options); - + imageSource.release() let bufferData = new ArrayBuffer(data.getPixelBytesNumber()); let bufferNewData = new ArrayBuffer(data.getPixelBytesNumber()); await data.readPixelsToBuffer(bufferData); diff --git a/imageknife/src/main/ets/components/imageknife/transform/InvertFilterTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/InvertFilterTransformation.ets index 7fcefc0..c8a3e8c 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/InvertFilterTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/InvertFilterTransformation.ets @@ -77,7 +77,7 @@ export class InvertFilterTransformation implements BaseTransform { } let data:PixelMap = await imageSource.createPixelMap(options); - + imageSource.release() let bufferData = new ArrayBuffer(data.getPixelBytesNumber()); await data.readPixelsToBuffer(bufferData); diff --git a/imageknife/src/main/ets/components/imageknife/transform/KuwaharaFilterTransform.ets b/imageknife/src/main/ets/components/imageknife/transform/KuwaharaFilterTransform.ets index edc89a7..2ecefa9 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/KuwaharaFilterTransform.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/KuwaharaFilterTransform.ets @@ -79,10 +79,12 @@ export class KuwaharaFilterTransform implements BaseTransform { imageSource.createPixelMap(options) .then((data) => { this.kuwahara(data, targetWidth, targetHeight, func); + imageSource.release() }) .catch((e:BusinessError) => { LogUtil.log(Constants.PROJECT_TAG + ";error:" + e); func?.asyncTransform(e, null); + imageSource.release() }) }}) } diff --git a/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets index 4c04a40..d02ff33 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets @@ -79,9 +79,11 @@ export class MaskTransformation implements BaseTransform { imageSource.createPixelMap(options) .then(data => { this.openInternal(data, targetWidth, targetHeight, func) + imageSource.release() }) .catch((e:BusinessError )=> { func?.asyncTransform(e, null); + imageSource.release() }) } diff --git a/imageknife/src/main/ets/components/imageknife/transform/PixelationFilterTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/PixelationFilterTransformation.ets index 7c45c72..ff67eba 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/PixelationFilterTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/PixelationFilterTransformation.ets @@ -80,9 +80,11 @@ export class PixelationFilterTransformation implements BaseTransform { } else { pixelUtils.pixel(data, this._mPixel, func); } + imageSource.release() }) .catch((e:BusinessError) => { LogUtil.log(Constants.PROJECT_TAG + ";error:" + e); + imageSource.release(); func?.asyncTransform(e, null); }) }}) diff --git a/imageknife/src/main/ets/components/imageknife/transform/RotateImageTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/RotateImageTransformation.ets index 00f35a5..6286720 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/RotateImageTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/RotateImageTransformation.ets @@ -70,9 +70,11 @@ export class RotateImageTransformation implements BaseTransform { imageSource.createPixelMap(options) .then((data) => { func?.asyncTransform("", data); + imageSource.release() }) .catch((e:BusinessError) => { LogUtil.log(Constants.PROJECT_TAG + ";error:" + e); + imageSource.release() func?.asyncTransform(e, null); }) }}) diff --git a/imageknife/src/main/ets/components/imageknife/transform/RoundedCornersTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/RoundedCornersTransformation.ets index 097ab06..74bd119 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/RoundedCornersTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/RoundedCornersTransformation.ets @@ -113,8 +113,10 @@ export class RoundedCornersTransformation implements BaseTransform { if (func != undefined && this.mTransform_pixelMap != undefined) { func?.asyncTransform("", this.mTransform_pixelMap); } + imageSource.release() }) .catch((error:BusinessError) => { + imageSource.release() LogUtil.log(Constants.PROJECT_TAG + "RoundedCornersTransformation error:" + error); }); }) diff --git a/imageknife/src/main/ets/components/imageknife/transform/SepiaFilterTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/SepiaFilterTransformation.ets index 72fbe75..87380d0 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/SepiaFilterTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/SepiaFilterTransformation.ets @@ -73,7 +73,7 @@ export class SepiaFilterTransformation implements BaseTransform { } } let data:PixelMap = await imageSource.createPixelMap(options); - + imageSource.release(); let bufferData = new ArrayBuffer(data.getPixelBytesNumber()); await data.readPixelsToBuffer(bufferData); diff --git a/imageknife/src/main/ets/components/imageknife/transform/SketchFilterTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/SketchFilterTransformation.ets index 1b3d72d..25d6f6c 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/SketchFilterTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/SketchFilterTransformation.ets @@ -66,9 +66,11 @@ export class SketchFilterTransformation implements BaseTransform { } else { CalculatePixelUtils.sketch(data, func); } + imageSource.release() }) .catch((e:BusinessError) => { func?.asyncTransform(e, null); + imageSource.release() }) }}) } diff --git a/imageknife/src/main/ets/components/imageknife/transform/SwirlFilterTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/SwirlFilterTransformation.ets index bc2b174..5681f1e 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/SwirlFilterTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/SwirlFilterTransformation.ets @@ -81,8 +81,10 @@ export class SwirlFilterTransformation implements BaseTransform { imageSource.createPixelMap(options) .then((data) => { this.swirl(data, this.radius, request, func); + imageSource.release(); }) .catch((e:BusinessError) => { + imageSource.release(); func?.asyncTransform(e, null); }) }}) diff --git a/imageknife/src/main/ets/components/imageknife/transform/ToonFilterTransform.ets b/imageknife/src/main/ets/components/imageknife/transform/ToonFilterTransform.ets index 7c7d83d..cb75d92 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/ToonFilterTransform.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/ToonFilterTransform.ets @@ -83,9 +83,11 @@ export class ToonFilterTransform implements BaseTransform { } imageSource.createPixelMap(options) .then((data) => { + imageSource.release() this.toon(data, targetWidth, targetHeight, func); }) .catch((e:BusinessError) => { + imageSource.release() LogUtil.log(Constants.PROJECT_TAG + ";error:" + e); func?.asyncTransform(e, null); }) diff --git a/imageknife/src/main/ets/components/imageknife/transform/TransformUtils.ets b/imageknife/src/main/ets/components/imageknife/transform/TransformUtils.ets index 1cd859f..a0876ac 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/TransformUtils.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/TransformUtils.ets @@ -63,7 +63,9 @@ export class TransformUtils { editable: true, rotate: degreesToRotate } - return imageSource.createPixelMap(options); + let promise:Promise = imageSource.createPixelMap(options); + imageSource.release() + return promise; } static centerInside(buf: ArrayBuffer, outWidth: number, outHeihgt: number, @@ -74,7 +76,9 @@ export class TransformUtils { let pw = p.size.width; let ph = p.size.height; if (pw <= outWidth && ph <= outHeihgt) { - callback?.asyncTransform('', imageSource.createPixelMap()); + let promise:Promise = imageSource.createPixelMap() + imageSource.release() + callback?.asyncTransform('', promise); } else { TransformUtils.fitCenter(buf, outWidth, outHeihgt, callback); } @@ -112,7 +116,9 @@ export class TransformUtils { desiredSize: { width: targetWidth, height: targetHeight } } if (callback) { - callback.asyncTransform('', imageSource.createPixelMap(options)); + let promise:Promise = imageSource.createPixelMap(options); + imageSource.release(); + callback.asyncTransform('', promise); } }) .catch((e:BusinessError) => { diff --git a/imageknife/src/main/ets/components/imageknife/transform/VignetteFilterTransform.ets b/imageknife/src/main/ets/components/imageknife/transform/VignetteFilterTransform.ets index c49897d..d1937ce 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/VignetteFilterTransform.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/VignetteFilterTransform.ets @@ -88,8 +88,10 @@ export class VignetteFilterTransform implements BaseTransform { imageSource.createPixelMap(options) .then((data) => { this.vignette(data, targetWidth, targetHeight, func); + imageSource.release(); }) .catch((e:BusinessError) => { + imageSource.release() LogUtil.log(Constants.PROJECT_TAG + ";error:" + e); func?.asyncTransform(e, null); }) diff --git a/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets b/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets index 51ca851..75e450e 100644 --- a/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets +++ b/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets @@ -57,7 +57,8 @@ export class FileTypeUtil { getFileType(file: ArrayBuffer): string | null { const fileData = new Uint8Array(file); - for (const fileType in this.fileSignatureMap) { + + Object.keys(this.fileSignatureMap).map((fileType)=>{ const bufferList = this.fileSignatureMap[fileType]; for (let i = 0; i < bufferList.length; i++) { let signature = bufferList[i]; @@ -65,8 +66,7 @@ export class FileTypeUtil { return fileType; } } - } - + }) return null; // 若无法识别文件类型,返回null } diff --git a/imageknife/src/main/ets/components/imageknife/utils/ParseImageUtil.ets b/imageknife/src/main/ets/components/imageknife/utils/ParseImageUtil.ets index a4264f6..9e43f20 100644 --- a/imageknife/src/main/ets/components/imageknife/utils/ParseImageUtil.ets +++ b/imageknife/src/main/ets/components/imageknife/utils/ParseImageUtil.ets @@ -48,6 +48,7 @@ export class ParseImageUtil implements IParseImage { } else { onCompleteFunction(pixelmap); } + imageSource.release() }) })