1.ArkTs语法适配
2.新增MemoryLruCache主动释放PixelMap对象,所有的imageSource主动调用release释放native内存 3.解决:pngj展示demo测试页面赋值错误引入闪退问题 4.demo页面不再允许超出三方库export暴露对象的访问,自检修复export对象是否准确,demo使用三方库import是否正确 Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
parent
ad2c0ed0a1
commit
21180245a0
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -120,7 +120,8 @@ struct PngjTestCasePage {
|
|||
name: 'readPngImageAsync'
|
||||
})
|
||||
pngj.readPngImageAsync(png_worker, this.pngSource2!, {pngCallback: (sender:ArrayBuffer, value:Record<string,Object>) => {
|
||||
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;
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import { ImageKnife } from '../imageknife/ImageKnife';
|
||||
import { ImageKnifeData } from '../imageknife/ImageKnifeData';
|
||||
import { LruCache } from './LruCache';
|
||||
|
||||
export class MemoryLruCache extends LruCache<string, ImageKnifeData>{
|
||||
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--
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<string, ImageKnifeData>;
|
||||
memoryCache: MemoryLruCache;
|
||||
diskMemoryCache: DiskLruCache;
|
||||
dataFetch: IDataFetch;
|
||||
resourceFetch: IResourceFetch<ArrayBuffer>;
|
||||
|
@ -78,7 +78,7 @@ export class ImageKnife {
|
|||
this.pausedMaps = new EasyLinkedHashMap();
|
||||
|
||||
// 构造方法传入size 为保存文件个数
|
||||
this.memoryCache = new LruCache<string, ImageKnifeData>(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<string, ImageKnifeData> {
|
||||
getMemoryCache(): MemoryLruCache {
|
||||
return this.memoryCache;
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ export class ImageKnife {
|
|||
return ImageKnifeGlobal.getInstance().getHapContext();
|
||||
}
|
||||
|
||||
setMemoryCache(lrucache: LruCache<string, ImageKnifeData>) {
|
||||
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<string, ImageKnifeData>(size);
|
||||
this.memoryCache = new MemoryLruCache(size);
|
||||
} else {
|
||||
let newLruCache = new LruCache<string, ImageKnifeData>(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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -66,9 +66,11 @@ export namespace Crop {
|
|||
} else {
|
||||
func?.cropCallback("", data);
|
||||
}
|
||||
imageSource.release()
|
||||
})
|
||||
.catch((e:BusinessError) => {
|
||||
func?.cropCallback(e, null);
|
||||
imageSource.release()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -893,6 +893,7 @@ export class Options {
|
|||
if (readyCrop) {
|
||||
readyCrop();
|
||||
}
|
||||
imageSource.release()
|
||||
})
|
||||
|
||||
});
|
||||
|
|
|
@ -53,23 +53,28 @@ export class ErrorHolderManager<T> {
|
|||
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)
|
||||
|
|
|
@ -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<ArrayBuffer>();
|
||||
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}`)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -74,11 +74,13 @@ export class BlurTransformation implements BaseTransform<PixelMap> {
|
|||
} 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);
|
||||
})
|
||||
})
|
||||
}})
|
||||
}
|
||||
}
|
|
@ -76,7 +76,7 @@ export class BrightnessFilterTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
}
|
||||
let data = await imageSource.createPixelMap(options);
|
||||
|
||||
imageSource.release()
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
await data.readPixelsToBuffer(bufferData);
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ export class ContrastFilterTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
let data = await imageSource.createPixelMap(options);
|
||||
|
||||
imageSource.release()
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
await data.readPixelsToBuffer(bufferData);
|
||||
|
||||
|
|
|
@ -75,12 +75,14 @@ export class CropCircleTransformation implements BaseTransform<PixelMap> {
|
|||
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()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -93,12 +93,14 @@ export class CropCircleWithBorderTransformation implements BaseTransform<PixelMa
|
|||
imageSource.createPixelMap(options)
|
||||
.then((pixelMap:PixelMap) => {
|
||||
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()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -73,11 +73,13 @@ export class CropSquareTransformation implements BaseTransform<PixelMap> {
|
|||
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) => {
|
||||
|
|
|
@ -83,9 +83,11 @@ export class CropTransformation implements BaseTransform<PixelMap> {
|
|||
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);
|
||||
})
|
||||
}})
|
||||
|
|
|
@ -68,7 +68,7 @@ export class GrayscaleTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -77,7 +77,7 @@ export class InvertFilterTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
|
||||
let data:PixelMap = await imageSource.createPixelMap(options);
|
||||
|
||||
imageSource.release()
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
await data.readPixelsToBuffer(bufferData);
|
||||
|
||||
|
|
|
@ -79,10 +79,12 @@ export class KuwaharaFilterTransform implements BaseTransform<PixelMap> {
|
|||
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()
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
|
|
@ -79,9 +79,11 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
|
|||
imageSource.createPixelMap(options)
|
||||
.then(data => {
|
||||
this.openInternal(data, targetWidth, targetHeight, func)
|
||||
imageSource.release()
|
||||
})
|
||||
.catch((e:BusinessError )=> {
|
||||
func?.asyncTransform(e, null);
|
||||
imageSource.release()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -80,9 +80,11 @@ export class PixelationFilterTransformation implements BaseTransform<PixelMap> {
|
|||
} 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);
|
||||
})
|
||||
}})
|
||||
|
|
|
@ -70,9 +70,11 @@ export class RotateImageTransformation implements BaseTransform<PixelMap> {
|
|||
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);
|
||||
})
|
||||
}})
|
||||
|
|
|
@ -113,8 +113,10 @@ export class RoundedCornersTransformation implements BaseTransform<PixelMap> {
|
|||
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);
|
||||
});
|
||||
})
|
||||
|
|
|
@ -73,7 +73,7 @@ export class SepiaFilterTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
}
|
||||
let data:PixelMap = await imageSource.createPixelMap(options);
|
||||
|
||||
imageSource.release();
|
||||
let bufferData = new ArrayBuffer(data.getPixelBytesNumber());
|
||||
await data.readPixelsToBuffer(bufferData);
|
||||
|
||||
|
|
|
@ -66,9 +66,11 @@ export class SketchFilterTransformation implements BaseTransform<PixelMap> {
|
|||
} else {
|
||||
CalculatePixelUtils.sketch(data, func);
|
||||
}
|
||||
imageSource.release()
|
||||
})
|
||||
.catch((e:BusinessError) => {
|
||||
func?.asyncTransform(e, null);
|
||||
imageSource.release()
|
||||
})
|
||||
}})
|
||||
}
|
||||
|
|
|
@ -81,8 +81,10 @@ export class SwirlFilterTransformation implements BaseTransform<PixelMap> {
|
|||
imageSource.createPixelMap(options)
|
||||
.then((data) => {
|
||||
this.swirl(data, this.radius, request, func);
|
||||
imageSource.release();
|
||||
})
|
||||
.catch((e:BusinessError) => {
|
||||
imageSource.release();
|
||||
func?.asyncTransform(e, null);
|
||||
})
|
||||
}})
|
||||
|
|
|
@ -83,9 +83,11 @@ export class ToonFilterTransform implements BaseTransform<PixelMap> {
|
|||
}
|
||||
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);
|
||||
})
|
||||
|
|
|
@ -63,7 +63,9 @@ export class TransformUtils {
|
|||
editable: true,
|
||||
rotate: degreesToRotate
|
||||
}
|
||||
return imageSource.createPixelMap(options);
|
||||
let promise:Promise<PixelMap> = 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<PixelMap> = 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<PixelMap> = imageSource.createPixelMap(options);
|
||||
imageSource.release();
|
||||
callback.asyncTransform('', promise);
|
||||
}
|
||||
})
|
||||
.catch((e:BusinessError) => {
|
||||
|
|
|
@ -88,8 +88,10 @@ export class VignetteFilterTransform implements BaseTransform<PixelMap> {
|
|||
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);
|
||||
})
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ export class ParseImageUtil implements IParseImage<PixelMap> {
|
|||
} else {
|
||||
onCompleteFunction(pixelmap);
|
||||
}
|
||||
imageSource.release()
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue