diff --git a/build-profile.json5 b/build-profile.json5 index eca7ce7..fa5c415 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -8,12 +8,12 @@ "compatibleSdkVersion": 9 } ], - "buildModeSet":[ + "buildModeSet": [ { - "name":"debug" + "name": "debug" }, { - "name":"release" + "name": "release" } ] }, @@ -37,6 +37,18 @@ { "name": "gpu_transform", "srcPath": "./gpu_transform" + }, + { + "name": "library", + "srcPath": "./library", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] } ] } \ No newline at end of file diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index ee278ce..63a8f24 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -6,7 +6,7 @@ "repository": {}, "version": "2.1.1-rc.3", "dependencies": { - "@ohos/imageknife": "file:../imageknife", + "@ohos/libraryimageknife": "file:../library", "@ohos/disklrucache": "^2.0.2-rc.0" } } diff --git a/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets b/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets index ee6521b..81a6863 100644 --- a/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EngineKeyFactories, EngineKeyInterface, RequestOption } from '@ohos/imageknife' -import { ObjectKey } from '@ohos/imageknife'; +import { EngineKeyFactories, EngineKeyInterface, RequestOption } from '@ohos/libraryimageknife' +import { ObjectKey } from '@ohos/libraryimageknife'; export class CustomEngineKeyImpl implements EngineKeyInterface { redefineUrl: (loadSrc: string) => string; diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index c3d114b..3e816e7 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -15,7 +15,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; -import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife' +import {InitImageKnife, ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/libraryimageknife' import { CustomEngineKeyImpl } from './CustomEngineKeyImpl' import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl'; import { BusinessError } from '@ohos.base' @@ -38,7 +38,7 @@ export default class EntryAbility extends UIAbility { windowStage.loadContent('pages/index', (err:BusinessError, data:void) => { }); - ImageKnife.with(this.context); + InitImageKnife.init(this.context); let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() if(imageKnife != undefined) { diff --git a/entry/src/main/ets/pages/CacheRuleChangedPage.ets b/entry/src/main/ets/pages/CacheRuleChangedPage.ets index a5592c9..ce1ef94 100644 --- a/entry/src/main/ets/pages/CacheRuleChangedPage.ets +++ b/entry/src/main/ets/pages/CacheRuleChangedPage.ets @@ -17,7 +17,7 @@ import { ImageKnifeOption, RotateImageTransformation, RoundedCornersTransformation -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/OptionTestPage.ets b/entry/src/main/ets/pages/OptionTestPage.ets index 1c19004..6f7f6e2 100644 --- a/entry/src/main/ets/pages/OptionTestPage.ets +++ b/entry/src/main/ets/pages/OptionTestPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption,NONE,DiskStrategy } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption,NONE,DiskStrategy } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/SignatureTestPage.ets b/entry/src/main/ets/pages/SignatureTestPage.ets index f2a2551..177061d 100644 --- a/entry/src/main/ets/pages/SignatureTestPage.ets +++ b/entry/src/main/ets/pages/SignatureTestPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption, NONE, DiskStrategy } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption, NONE, DiskStrategy } from '@ohos/libraryimageknife' import { ObjectKey } from '@ohos/imageknife/src/main/ets/components/imageknife/ObjectKey'; @Entry diff --git a/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets b/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets index fb31384..cc787cc 100644 --- a/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets +++ b/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeOption,ImageKnifeComponent} from '@ohos/imageknife' +import {ImageKnifeOption,ImageKnifeComponent} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/basicTestFileIOPage.ets b/entry/src/main/ets/pages/basicTestFileIOPage.ets index 0a5fddd..7488325 100644 --- a/entry/src/main/ets/pages/basicTestFileIOPage.ets +++ b/entry/src/main/ets/pages/basicTestFileIOPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { FileUtils, ImageKnifeGlobal} from '@ohos/imageknife' +import { FileUtils, ImageKnifeGlobal} from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; diff --git a/entry/src/main/ets/pages/basicTestMediaImage.ets b/entry/src/main/ets/pages/basicTestMediaImage.ets index 089eec6..e448f79 100644 --- a/entry/src/main/ets/pages/basicTestMediaImage.ets +++ b/entry/src/main/ets/pages/basicTestMediaImage.ets @@ -13,12 +13,12 @@ * limitations under the License. */ import featureAbility from '@ohos.ability.featureAbility'; -import { FileUtils } from '@ohos/imageknife' -import { FileTypeUtil } from '@ohos/imageknife' +import { FileUtils } from '@ohos/libraryimageknife' +import { FileTypeUtil } from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; -import { Base64 } from '@ohos/imageknife' -import { ParseImageUtil } from '@ohos/imageknife' -import { ImageKnifeGlobal } from '@ohos/imageknife' +import { Base64 } from '@ohos/libraryimageknife' +import { ParseImageUtil } from '@ohos/libraryimageknife' +import { ImageKnifeGlobal } from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; @Entry diff --git a/entry/src/main/ets/pages/basicTestResourceManagerPage.ets b/entry/src/main/ets/pages/basicTestResourceManagerPage.ets index 824b00c..95de8fd 100644 --- a/entry/src/main/ets/pages/basicTestResourceManagerPage.ets +++ b/entry/src/main/ets/pages/basicTestResourceManagerPage.ets @@ -13,11 +13,11 @@ * limitations under the License. */ import featureAbility from '@ohos.ability.featureAbility'; -import {FileUtils} from '@ohos/imageknife' -import {FileTypeUtil} from '@ohos/imageknife' +import {FileUtils} from '@ohos/libraryimageknife' +import {FileTypeUtil} from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; -import {Base64} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' +import {Base64} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; @Entry diff --git a/entry/src/main/ets/pages/compressPage.ets b/entry/src/main/ets/pages/compressPage.ets index b76a7ba..578840a 100644 --- a/entry/src/main/ets/pages/compressPage.ets +++ b/entry/src/main/ets/pages/compressPage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnife} from '@ohos/imageknife' -import {OnRenameListener} from '@ohos/imageknife' -import {OnCompressListener} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {OnRenameListener} from '@ohos/libraryimageknife' +import {OnCompressListener} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/cropImagePage2.ets b/entry/src/main/ets/pages/cropImagePage2.ets index fc76184..df4ad5d 100644 --- a/entry/src/main/ets/pages/cropImagePage2.ets +++ b/entry/src/main/ets/pages/cropImagePage2.ets @@ -13,14 +13,14 @@ * limitations under the License. */ -import { CropImage } from '@ohos/imageknife' -import { CropOptions } from '@ohos/imageknife' -import { Crop } from '@ohos/imageknife' -import { RecourseProvider } from '@ohos/imageknife' -import { PixelMapCrop,Options } from '@ohos/imageknife' -import { CropCallback } from '@ohos/imageknife' -import { FileUtils } from '@ohos/imageknife' -import { ImageKnifeGlobal } from '@ohos/imageknife' +import { CropImage } from '@ohos/libraryimageknife' +import { CropOptions } from '@ohos/libraryimageknife' +import { Crop } from '@ohos/libraryimageknife' +import { RecourseProvider } from '@ohos/libraryimageknife' +import { PixelMapCrop,Options } from '@ohos/libraryimageknife' +import { CropCallback } from '@ohos/libraryimageknife' +import { FileUtils } from '@ohos/libraryimageknife' +import { ImageKnifeGlobal } from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' import resourceManager from '@ohos.resourceManager'; import common from '@ohos.app.ability.common' diff --git a/entry/src/main/ets/pages/dataShareUriLoadPage.ets b/entry/src/main/ets/pages/dataShareUriLoadPage.ets index 2a22952..fd3859f 100644 --- a/entry/src/main/ets/pages/dataShareUriLoadPage.ets +++ b/entry/src/main/ets/pages/dataShareUriLoadPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { ImageKnifeComponent, ImageKnifeOption, } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption, } from '@ohos/libraryimageknife' @Entry diff --git a/entry/src/main/ets/pages/drawFactoryTestPage.ets b/entry/src/main/ets/pages/drawFactoryTestPage.ets index 24bbb35..433475b 100644 --- a/entry/src/main/ets/pages/drawFactoryTestPage.ets +++ b/entry/src/main/ets/pages/drawFactoryTestPage.ets @@ -18,7 +18,7 @@ import { ImageKnifeOption, ImageKnifeDrawFactory, ScaleType -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/frescoRetryTestCasePage.ets b/entry/src/main/ets/pages/frescoRetryTestCasePage.ets index b44bfba..c6ae9d5 100644 --- a/entry/src/main/ets/pages/frescoRetryTestCasePage.ets +++ b/entry/src/main/ets/pages/frescoRetryTestCasePage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {RoundedCornersTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {RoundedCornersTransformation} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/gifTestCasePage.ets b/entry/src/main/ets/pages/gifTestCasePage.ets index 771a395..d45ffa3 100644 --- a/entry/src/main/ets/pages/gifTestCasePage.ets +++ b/entry/src/main/ets/pages/gifTestCasePage.ets @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {GIFParseImpl} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' +import {GIFParseImpl} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; import resourceManager from '@ohos.resourceManager'; import { BusinessError } from '@ohos.base' diff --git a/entry/src/main/ets/pages/hspCacheTestPage.ets b/entry/src/main/ets/pages/hspCacheTestPage.ets new file mode 100644 index 0000000..000f881 --- /dev/null +++ b/entry/src/main/ets/pages/hspCacheTestPage.ets @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023 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 { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/libraryimageknife' + +@Entry +@Component +struct Index { + + + @State imageOption1:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + + } + @State imageOption2:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + + } + @State imageOption3:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + + } + + build() { + Scroll() { + Column() { + Button('点击加载网络图片').onClick(()=>{ + this.imageOption2 = { + loadSrc: 'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB', + } + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption2}).width(300).height(300).backgroundColor(Color.Pink) + + Button('点击加载本地文件').onClick(()=>{ + let path = globalThis.ImageKnife.getImageKnifeContext().filesDir+"/set.jpeg"; + FileUtils.getInstance().readFilePicAsync(path).then(buffer=>{ + this.imageOption3 = { + loadSrc: path + } + }) + + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption3}).width(300).height(300).backgroundColor(Color.Pink) + + + + }.width('100%') + + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index ac79068..d527433 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -252,6 +252,26 @@ struct IndexFunctionDemo { .onClick(() => { router.pushUrl({ url: "pages/testGifLoadWithWorkerPage" }); }).margin({ top: 5, left: 3 }) + }.width('100%').height(60).backgroundColor(Color.Pink) + Text("HSP相关测试").fontSize(15) + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + + Button("进入HSP的library共享包") + .onClick(() => { + router.pushUrl({url:'@bundle:com.openharmony.imageknife/library/ets/pages/Index'}) + .then(()=>{ + console.log('push page suceess') + }).catch(err => { + console.log(`pushUrl failed, code is ${err.code}, message is ${err.message}`) + }) + }).margin({ top: 15 }) + Button("hsp加载后缓存情况,先点左侧按钮") + .onClick(() => { + console.log("pages/tempUrlTestPage 页面跳转") + router.pushUrl({ url: "pages/hspCacheTestPage" }); + }).margin({ top: 15 }) + + }.width('100%').height(60).backgroundColor(Color.Pink) Text("测试图片加载稳定").fontSize(15) Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { diff --git a/entry/src/main/ets/pages/index.ets b/entry/src/main/ets/pages/index.ets index 7d6dd99..9043edd 100644 --- a/entry/src/main/ets/pages/index.ets +++ b/entry/src/main/ets/pages/index.ets @@ -18,7 +18,7 @@ import { ImageKnifeOption, ImageKnifeGlobal, ImageKnife -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; import { ObjectKey } from '@ohos/imageknife/src/main/ets/components/imageknife/ObjectKey'; diff --git a/entry/src/main/ets/pages/manyPhotoShowPage.ets b/entry/src/main/ets/pages/manyPhotoShowPage.ets index 570a80f..dffbb0a 100644 --- a/entry/src/main/ets/pages/manyPhotoShowPage.ets +++ b/entry/src/main/ets/pages/manyPhotoShowPage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent, ScaleType} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent, ScaleType} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import {Material} from './model/Material' import {TestDataSource} from './model/TestDataSource' import {DiskLruCache} from '@ohos/disklrucache' diff --git a/entry/src/main/ets/pages/pngjTestCasePage.ets b/entry/src/main/ets/pages/pngjTestCasePage.ets index 15ec0fe..3e6cc0c 100644 --- a/entry/src/main/ets/pages/pngjTestCasePage.ets +++ b/entry/src/main/ets/pages/pngjTestCasePage.ets @@ -13,9 +13,9 @@ * limitations under the License. */ import router from '@system.router'; -import { Pngj } from '@ohos/imageknife' +import { Pngj } from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; -import { FileUtils,ImageKnifeGlobal } from '@ohos/imageknife' +import { FileUtils,ImageKnifeGlobal } from '@ohos/libraryimageknife' import featureability from '@ohos.ability.featureAbility' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker'; diff --git a/entry/src/main/ets/pages/showErrorholderTestCasePage.ets b/entry/src/main/ets/pages/showErrorholderTestCasePage.ets index ad82adf..15ea013 100644 --- a/entry/src/main/ets/pages/showErrorholderTestCasePage.ets +++ b/entry/src/main/ets/pages/showErrorholderTestCasePage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {RoundedCornersTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {RoundedCornersTransformation} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/storageTestLruCache.ets b/entry/src/main/ets/pages/storageTestLruCache.ets index abe8e07..018c002 100644 --- a/entry/src/main/ets/pages/storageTestLruCache.ets +++ b/entry/src/main/ets/pages/storageTestLruCache.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import {LruCache} from '@ohos/imageknife' +import {LruCache} from '@ohos/libraryimageknife' function getRandomInt(min:number, max:number):number { min = Math.ceil(min); diff --git a/entry/src/main/ets/pages/svgTestCasePage.ets b/entry/src/main/ets/pages/svgTestCasePage.ets index 6157a96..edcd299 100644 --- a/entry/src/main/ets/pages/svgTestCasePage.ets +++ b/entry/src/main/ets/pages/svgTestCasePage.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {SVGParseImpl} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' +import {SVGParseImpl} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; import {BusinessError} from '@ohos.base' import common from '@ohos.app.ability.common'; diff --git a/entry/src/main/ets/pages/tempUrlTestPage.ets b/entry/src/main/ets/pages/tempUrlTestPage.ets index 3353fdc..8057c30 100644 --- a/entry/src/main/ets/pages/tempUrlTestPage.ets +++ b/entry/src/main/ets/pages/tempUrlTestPage.ets @@ -20,7 +20,7 @@ import { ImageKnife, ImageKnifeDrawFactory, ScaleType -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; @Entry @Component diff --git a/entry/src/main/ets/pages/testAllCacheInfoPage.ets b/entry/src/main/ets/pages/testAllCacheInfoPage.ets index 9d5003f..f39920a 100644 --- a/entry/src/main/ets/pages/testAllCacheInfoPage.ets +++ b/entry/src/main/ets/pages/testAllCacheInfoPage.ets @@ -12,14 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {RequestOption} from '@ohos/imageknife' -import {ImageKnifeData} from '@ohos/imageknife' -import {AllCacheInfo,IAllCacheInfoCallback} from '@ohos/imageknife' -import {ImageKnifeComponent} from '@ohos/imageknife' -import {TransformType} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {RequestOption} from '@ohos/libraryimageknife' +import {ImageKnifeData} from '@ohos/libraryimageknife' +import {AllCacheInfo,IAllCacheInfoCallback} from '@ohos/libraryimageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {TransformType} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import {BusinessError} from '@ohos.base' @Entry @Component diff --git a/entry/src/main/ets/pages/testGifDontAnimatePage.ets b/entry/src/main/ets/pages/testGifDontAnimatePage.ets index 69a56cc..3ba4ae7 100644 --- a/entry/src/main/ets/pages/testGifDontAnimatePage.ets +++ b/entry/src/main/ets/pages/testGifDontAnimatePage.ets @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import worker from '@ohos.worker' @Entry @Component diff --git a/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets index 3f044a4..5753429 100644 --- a/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets +++ b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnife,ImageKnifeGlobal, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnife,ImageKnifeGlobal, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife' import worker, { MessageEvents } from '@ohos.worker' import Prompt from '@system.prompt' diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets index 687a98b..8298de4 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker' @Entry diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets index 1966689..44c646f 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {BaseTransform} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {GrayscaleTransformation} from '@ohos/imageknife' -import {SketchFilterTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {BaseTransform} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {GrayscaleTransformation} from '@ohos/libraryimageknife' +import {SketchFilterTransformation} from '@ohos/libraryimageknife' import image from '@ohos.multimedia.image' @Entry diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets index 8871b1a..0079d94 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets @@ -12,17 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' -import {ScaleType} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {GrayscaleTransformation} from '@ohos/imageknife' -import {SketchFilterTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {ScaleType} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {GrayscaleTransformation} from '@ohos/libraryimageknife' +import {SketchFilterTransformation} from '@ohos/libraryimageknife' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker' -import {BaseTransform} from '@ohos/imageknife' +import {BaseTransform} from '@ohos/libraryimageknife' import image from '@ohos.multimedia.image' @Entry @Component diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets index 5585b14..fd11e45 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets @@ -24,7 +24,7 @@ import { ScaleType, ImageKnifeGlobal, BaseTransform -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker'; import image from '@ohos.multimedia.image'; diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets index ef672cd..d3de95f 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets @@ -25,7 +25,7 @@ import { IDrawLifeCycle, ScaleType, ImageKnifeDrawFactory -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; @Entry @Component diff --git a/entry/src/main/ets/pages/testPreloadPage.ets b/entry/src/main/ets/pages/testPreloadPage.ets index 7924e71..f8e1098 100644 --- a/entry/src/main/ets/pages/testPreloadPage.ets +++ b/entry/src/main/ets/pages/testPreloadPage.ets @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeData} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {RequestOption} from '@ohos/imageknife' -import {ImageKnifeGlobal } from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeData} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {RequestOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal } from '@ohos/libraryimageknife' import worker from '@ohos.worker' import { BusinessError } from '@ohos.base' diff --git a/entry/src/main/ets/pages/testSingleFrameGifPage.ets b/entry/src/main/ets/pages/testSingleFrameGifPage.ets index 0e292c6..7e7a8f7 100644 --- a/entry/src/main/ets/pages/testSingleFrameGifPage.ets +++ b/entry/src/main/ets/pages/testSingleFrameGifPage.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent } from '@ohos/imageknife' -import { ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnifeComponent } from '@ohos/libraryimageknife' +import { ImageKnifeOption } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/transformPixelMapPage.ets b/entry/src/main/ets/pages/transformPixelMapPage.ets index 226b8ed..96d47d7 100644 --- a/entry/src/main/ets/pages/transformPixelMapPage.ets +++ b/entry/src/main/ets/pages/transformPixelMapPage.ets @@ -12,28 +12,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { RequestOption,ImageKnifeGlobal} from '@ohos/imageknife' -import { CropCircleTransformation } from '@ohos/imageknife' -import { RoundedCornersTransformation } from '@ohos/imageknife' +import { RequestOption,ImageKnifeGlobal} from '@ohos/libraryimageknife' +import { CropCircleTransformation } from '@ohos/libraryimageknife' +import { RoundedCornersTransformation } from '@ohos/libraryimageknife' import { CropCircleWithBorderTransformation -} from '@ohos/imageknife' -import { RotateImageTransformation } from '@ohos/imageknife' -import { CropSquareTransformation } from '@ohos/imageknife' -import { CropTransformation } from '@ohos/imageknife' -import { CropType } from '@ohos/imageknife' -import { GrayscaleTransformation } from '@ohos/imageknife' -import { BrightnessFilterTransformation } from '@ohos/imageknife' -import { ContrastFilterTransformation } from '@ohos/imageknife' -import { InvertFilterTransformation } from '@ohos/imageknife' -import { SepiaFilterTransformation } from '@ohos/imageknife' -import { SketchFilterTransformation } from '@ohos/imageknife' -import { BlurTransformation } from '@ohos/imageknife' -import { PixelationFilterTransformation } from '@ohos/imageknife' -import { MaskTransformation } from '@ohos/imageknife' -import { SwirlFilterTransformation } from '@ohos/imageknife' +} from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation' +import { RotateImageTransformation } from '@ohos/libraryimageknife' +import { CropSquareTransformation } from '@ohos/libraryimageknife' +import { CropTransformation } from '@ohos/libraryimageknife' +import { CropType } from '@ohos/libraryimageknife' +import { GrayscaleTransformation } from '@ohos/libraryimageknife' +import { BrightnessFilterTransformation } from '@ohos/libraryimageknife' +import { ContrastFilterTransformation } from '@ohos/libraryimageknife' +import { InvertFilterTransformation } from '@ohos/libraryimageknife' +import { SepiaFilterTransformation } from '@ohos/libraryimageknife' +import { SketchFilterTransformation } from '@ohos/libraryimageknife' +import { BlurTransformation } from '@ohos/libraryimageknife' +import { PixelationFilterTransformation } from '@ohos/libraryimageknife' +import { MaskTransformation } from '@ohos/libraryimageknife' +import { SwirlFilterTransformation } from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' -import {ImageKnifeData} from '@ohos/imageknife' +import {ImageKnifeData} from '@ohos/libraryimageknife' /** * PixelMap transform 示例 */ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 8332d5c..df309dd 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -33,6 +33,7 @@ "pages/testGifLoadWithWorkerPage", "pages/OptionTestPage", "pages/SignatureTestPage", + "pages/hspCacheTestPage", "pages/testManyNetImageLoadWithPage", "pages/testManyGifLoadWithPage" ] diff --git a/entry/src/ohosTest/ets/test/imageknife.test.ets b/entry/src/ohosTest/ets/test/imageknife.test.ets index 368a7a6..2186d29 100644 --- a/entry/src/ohosTest/ets/test/imageknife.test.ets +++ b/entry/src/ohosTest/ets/test/imageknife.test.ets @@ -14,7 +14,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife' +import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/libraryimageknife' export default function ImageKnifeTest() { describe('ImageKnifeTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/logutil.test.ets b/entry/src/ohosTest/ets/test/logutil.test.ets index 71f61a1..4ab90ac 100644 --- a/entry/src/ohosTest/ets/test/logutil.test.ets +++ b/entry/src/ohosTest/ets/test/logutil.test.ets @@ -14,7 +14,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {LogUtil} from '@ohos/imageknife' +import {LogUtil} from '@ohos/libraryimageknife' export default function LogUtilTest() { describe('LogUtilTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/lrucache.test.ets b/entry/src/ohosTest/ets/test/lrucache.test.ets index 3238954..b5ef887 100644 --- a/entry/src/ohosTest/ets/test/lrucache.test.ets +++ b/entry/src/ohosTest/ets/test/lrucache.test.ets @@ -14,7 +14,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {LruCache} from '@ohos/imageknife' // DiskLruCache用例由DiskLruCache三方库提供 +import {LruCache} from '@ohos/libraryimageknife' // DiskLruCache用例由DiskLruCache三方库提供 export default function lruCacheTest() { describe('lruCacheTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/requestoption.test.ets b/entry/src/ohosTest/ets/test/requestoption.test.ets index e2b0621..b83bd10 100644 --- a/entry/src/ohosTest/ets/test/requestoption.test.ets +++ b/entry/src/ohosTest/ets/test/requestoption.test.ets @@ -15,7 +15,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {RequestOption,Size} from '@ohos/imageknife' +import {RequestOption,Size} from '@ohos/libraryimageknife' export default function RequestOptionTest() { describe('RequestOptionTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/transfrom.test.ets b/entry/src/ohosTest/ets/test/transfrom.test.ets index 8802154..c1b1e8c 100644 --- a/entry/src/ohosTest/ets/test/transfrom.test.ets +++ b/entry/src/ohosTest/ets/test/transfrom.test.ets @@ -36,7 +36,7 @@ import { ToonFilterTransform, VignetteFilterTransform, -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' export default function Transform() { describe('Transform', ()=>{ diff --git a/entry/src/ohosTest/ets/testability/TestAbility.ets b/entry/src/ohosTest/ets/testability/TestAbility.ets index 22b0877..140dbda 100644 --- a/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -18,7 +18,7 @@ import hilog from '@ohos.hilog'; import { Hypium } from '@ohos/hypium'; import testsuite from '../test/List.test'; import window from '@ohos.window'; -import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife' +import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/libraryimageknife' import AbilityConstant from '@ohos.app.ability.AbilityConstant'; import Want from '@ohos.app.ability.Want'; import { BusinessError } from '@ohos.base' diff --git a/imageknife/index.ets b/imageknife/index.ets index 1dbd5ef..77c9908 100644 --- a/imageknife/index.ets +++ b/imageknife/index.ets @@ -97,6 +97,7 @@ 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 {ObjectKey} from './src/main/ets/components/imageknife/ObjectKey' export { ImageKnifeComponent, ScaleType, ScaleTypeHelper } from './src/main/ets/components/imageknife/ImageKnifeComponent' export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory' export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions} from './src/main/ets/components/imageknife/ImageKnifeOption' diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index 37d80b7..7f1a64c 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -22,6 +22,7 @@ import { GIFFrame } from '../imageknife/utils/gif/GIFFrame' import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle' import { LogUtil } from '../imageknife/utils/LogUtil' import { BusinessError } from '@ohos.base' +import common from '@ohos.app.ability.common' @Component export struct ImageKnifeComponent { @@ -260,6 +261,14 @@ export struct ImageKnifeComponent { } } + configHspContext(request: RequestOption){ + if(this.imageKnifeOption.context != undefined){ + request.setModuleContext(this.imageKnifeOption.context) + }else{ + request.setModuleContext(getContext(this) as common.UIAbilityContext) + } + } + configRenderGpu(request: RequestOption) { if (this.imageKnifeOption.enableGpu) { request.enableGPU() @@ -285,6 +294,7 @@ export struct ImageKnifeComponent { this.configNecessary(request); this.configCacheStrategy(request); this.configDisplay(request); + this.configHspContext(request) this.configRenderGpu(request); if(ImageKnifeGlobal.getInstance().getImageKnife()!=undefined) { ImageKnifeGlobal.getInstance().getImageKnife()?.call(request); diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets index 2180386..0c4e00d 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets @@ -25,6 +25,7 @@ import { ScaleType } from '../imageknife/ImageKnifeComponent' import { rgbColor } from './transform/CropCircleWithBorderTransformation' import { RoundCorner } from './transform/RoundedCornersTransformation' import { ObjectKey } from './ObjectKey' +import common from '@ohos.app.ability.common' export interface CropCircleWithBorder{ border: number, @@ -125,7 +126,7 @@ export class ImageKnifeOption { allCacheInfoCallback?: IAllCacheInfoCallback; - + context?: common.UIAbilityContext; // sizeAnimate?: AnimateParam 由业务自定义不再支持 constructor() { diff --git a/imageknife/src/main/ets/components/imageknife/RequestOption.ets b/imageknife/src/main/ets/components/imageknife/RequestOption.ets index d7e7c3f..131dd94 100644 --- a/imageknife/src/main/ets/components/imageknife/RequestOption.ets +++ b/imageknife/src/main/ets/components/imageknife/RequestOption.ets @@ -49,6 +49,7 @@ import { LogUtil } from '../imageknife/utils/LogUtil' import { ImageKnifeGlobal } from './ImageKnifeGlobal' import { BusinessError } from '@ohos.base' import { ObjectKey } from './ObjectKey' +import common from '@ohos.app.ability.common' export interface Size { width: number, @@ -130,7 +131,8 @@ export class RequestOption { } } } - + // module资源的需要当前的module context + moduleContext:common.UIAbilityContext; constructor() { // 初始化全局监听 this.requestListeners = new Array(); @@ -147,7 +149,13 @@ export class RequestOption { }); return uuid; } + setModuleContext(moduleCtx:common.UIAbilityContext){ + this.moduleContext = moduleCtx; + } + getModuleContext():common.UIAbilityContext{ + return this.moduleContext; + } /** * set image Component size */ diff --git a/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets b/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets index 9732a7b..41f73c2 100644 --- a/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets +++ b/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets @@ -77,7 +77,7 @@ export class ErrorHolderManager { onError("ErrorHolderManager 文件类型为null,请检查数据源arraybuffer") } } - resourceFetch.loadResource(res, suc, onError) + resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError) } else { onError("ErrorHolderManager 输入参数有问题!") } diff --git a/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets b/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets index 612a10f..80f4c50 100644 --- a/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets +++ b/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets @@ -73,7 +73,7 @@ export class PlaceHolderManager { break; } } - resourceFetch.loadResource(res, suc, onError) + resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError) } else { onError("PlaceHolderManager 输入参数有问题!") } diff --git a/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets b/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets index aaf2245..f769ea6 100644 --- a/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets +++ b/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets @@ -73,7 +73,7 @@ export class RetryHolderManager { break; } } - resourceFetch.loadResource(res, suc, onError) + resourceFetch.loadResource(this.options.getModuleContext(), res, suc, onError) } else { onError("PlaceHolderManager 输入参数有问题!") } diff --git a/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets b/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets index 6733caa..ae7d9c5 100644 --- a/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets +++ b/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets @@ -43,7 +43,7 @@ export class NetworkDownloadClient implements IDataFetch { enableMetered: true, }; - loadRequest.downloadFile( (ImageKnifeGlobal.getInstance().getHapContext() as common.BaseContext ), downloadConfig).then((downloadTask:loadRequest.DownloadTask) => { + loadRequest.downloadFile( (request.getModuleContext() as common.BaseContext ), downloadConfig).then((downloadTask:loadRequest.DownloadTask) => { if (downloadTask) { let loadTask:loadRequest.DownloadTask | null = downloadTask; diff --git a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets index a7615ba..0a545cc 100644 --- a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets +++ b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets @@ -241,7 +241,7 @@ export class RequestManager { } } } - this.mIResourceFetch.loadResource(request.loadSrc as Resource, success, onError); + this.mIResourceFetch.loadResource(request.getModuleContext(),request.loadSrc as Resource, success, onError); } // 加载磁盘缓存 原图 private loadDiskFromSource(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike, onError:(reason?:BusinessError|string)=>void) { @@ -323,6 +323,7 @@ export class RequestManager { width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width), height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height) }) + thumbOption.setModuleContext(this.options.getModuleContext()) let thumbCallback = this.options.thumbholderOnComplete; let thumbError = this.options.thumbholderOnError; this.options.transformations[0].transform(source, thumbOption,{asyncTransform: (error:BusinessError|string, pixelMap: PixelMap|null) => { @@ -552,6 +553,7 @@ export class RequestManager { thumbnailProcess(source:ArrayBuffer, filetype:string, onComplete:(value:ImageKnifeData)=>void|PromiseLike, onError:(reason?:BusinessError|string)=>void){ let thumbOption = new RequestOption(); + thumbOption.setModuleContext(this.options.getModuleContext()) thumbOption.setImageViewSize({ width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width), height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height) diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets index 70057e5..1c65221 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets @@ -14,7 +14,9 @@ */ import { BusinessError } from '@ohos.base' +import common from '@ohos.app.ability.common'; + // 本地资源解析抽象接口 export interface IResourceFetch { - loadResource:(res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void)=>void; + loadResource:(context:common.UIAbilityContext ,res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void)=>void; } \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets index fd27e74..6faadc2 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets @@ -20,11 +20,11 @@ import { ImageKnifeGlobal } from '../ImageKnifeGlobal'; import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; export class ParseResClient implements IResourceFetch { - loadResource(res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void) { + loadResource(context:common.UIAbilityContext,res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void) { let resId = res.id; let resType = res.type; if (resType == ResourceTypeEts.MEDIA) { - ((ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext).resourceManager as resourceManager.ResourceManager) + (context.resourceManager as resourceManager.ResourceManager) .getMediaContent(resId) .then(data => { let arrayBuffer = this.typedArrayToBuffer(data); diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets index 6f563b5..983a982 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets @@ -19,14 +19,14 @@ import { Base64 } from '../../cache/Base64' import { BusinessError } from '@ohos.base' import resourceManager from '@ohos.resourceManager'; import { ImageKnifeGlobal } from '../ImageKnifeGlobal'; +import common from '@ohos.app.ability.common' export class ParseResClientBase64 implements IResourceFetch { - loadResource(res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike, onErrorFunction: (reason?: BusinessError | string) => void) { + loadResource(context:common.UIAbilityContext,res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike, onErrorFunction: (reason?: BusinessError | string) => void) { let resId = res.id; let resType = res.type; if (resType == ResourceTypeEts.MEDIA) { - ((ImageKnifeGlobal.getInstance() - .getHapContext() as Record).resourceManager as resourceManager.ResourceManager) + (context.resourceManager as resourceManager.ResourceManager) .getMediaContentBase64(resId) .then(data => { let matchReg = ';base64,'; diff --git a/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets index d02ff33..f537bce 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets @@ -87,13 +87,13 @@ export class MaskTransformation implements BaseTransform { }) } - private openInternal(bitmap: PixelMap, width: number, height: number, func?: AsyncTransform) { + private openInternal(request: RequestOption,bitmap: PixelMap, width: number, height: number, func?: AsyncTransform) { if (!this._mResourceData) { if(func != undefined){ func.asyncTransform("MaskTransformation resource is empty", null) } } - let context = (ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext) + let context = (request.getModuleContext() as common.UIAbilityContext) if(context != undefined){ let resourceManager = context.resourceManager as resourceManager.ResourceManager if(resourceManager != undefined && this._mResourceData != undefined) diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/library/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/library/build-profile.json5 b/library/build-profile.json5 new file mode 100644 index 0000000..befa101 --- /dev/null +++ b/library/build-profile.json5 @@ -0,0 +1,10 @@ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} \ No newline at end of file diff --git a/library/hvigorfile.ts b/library/hvigorfile.ts new file mode 100644 index 0000000..0e65ea8 --- /dev/null +++ b/library/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hspTasks diff --git a/library/oh-package.json5 b/library/oh-package.json5 new file mode 100644 index 0000000..beeccdc --- /dev/null +++ b/library/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "library", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": { + "@ohos/imageknife": "file:../imageknife" + } +} \ No newline at end of file diff --git a/library/src/main/ets/Index.ets b/library/src/main/ets/Index.ets new file mode 100644 index 0000000..c526015 --- /dev/null +++ b/library/src/main/ets/Index.ets @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2023 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. + */ + + +// ImageKnife 对外暴露的接口由library提供 + +/** + * cache + */ + +export { FileUtils } from '@ohos/imageknife' +export { Base64 } from '@ohos/imageknife' +export { LruCache } from '@ohos/imageknife' +export { DiskStrategy } from '@ohos/imageknife' +export { ALL } from '@ohos/imageknife' +export { AUTOMATIC } from '@ohos/imageknife' +export { DATA } from '@ohos/imageknife' +export { NONE } from '@ohos/imageknife' +export { RESOURCE } from '@ohos/imageknife' +export { EngineKeyInterface } from '@ohos/imageknife' +export { EngineKeyFactories } from '@ohos/imageknife' + +/** + * compress + */ +export { CompressBuilder } from '@ohos/imageknife' +export { OnCompressListener } from '@ohos/imageknife' +export { OnRenameListener } from '@ohos/imageknife' +export { CompressDataListener } from '@ohos/imageknife' +export { CompressionPredicate } from '@ohos/imageknife' +export { CompressAdapter } from '@ohos/imageknife' +export { CompressProvider } from '@ohos/imageknife' +export { DataStringPathProvider } from '@ohos/imageknife' +export { RecourseProvider } from '@ohos/imageknife' + +/** + * crop + */ + +export { CropImage } from '@ohos/imageknife' +export { CropOptions } from '@ohos/imageknife' +export { PixelMapCrop,Options } from '@ohos/imageknife' +export { CropCallback } from '@ohos/imageknife' + +/** + * transform + */ +export { BaseTransform } from '@ohos/imageknife' +export { BlurTransformation } from '@ohos/imageknife' +export { BrightnessFilterTransformation } from '@ohos/imageknife' +export { ContrastFilterTransformation } from '@ohos/imageknife' +export { CropCircleTransformation } from '@ohos/imageknife' +export { CropCircleWithBorderTransformation,rgbColor } from '@ohos/imageknife' +export { CropSquareTransformation } from '@ohos/imageknife' +export { CropTransformation,CropType } from '@ohos/imageknife' +export { GrayscaleTransformation } from '@ohos/imageknife' +export { InvertFilterTransformation } from '@ohos/imageknife' +export { PixelationFilterTransformation } from '@ohos/imageknife' +export { RotateImageTransformation } from '@ohos/imageknife' +export { RoundedCornersTransformation,RoundCorner } from '@ohos/imageknife' +export { SepiaFilterTransformation } from '@ohos/imageknife' +export { SketchFilterTransformation } from '@ohos/imageknife' +export { MaskTransformation } from '@ohos/imageknife' +export { SwirlFilterTransformation } from '@ohos/imageknife' +export { KuwaharaFilterTransform } from '@ohos/imageknife' +export { ToonFilterTransform } from '@ohos/imageknife' +export { VignetteFilterTransform } from '@ohos/imageknife' +export { TransformUtils } from '@ohos/imageknife' +export { TransformType } from '@ohos/imageknife' +export { CenterCrop } from '@ohos/imageknife' +export { CenterInside } from '@ohos/imageknife' +export { FitCenter } from '@ohos/imageknife' + +/** + * pngj + */ +export { Pngj } from '@ohos/imageknife' +export {handler} from '@ohos/imageknife' +export { UPNG } from '@ohos/imageknife' + + + +/** + * ImageKnife + */ +export { ImageKnife } from '@ohos/imageknife' +export { ImageKnifeGlobal } from '@ohos/imageknife' +export {RequestOption,Size} from '@ohos/imageknife' +export {ObjectKey} from '@ohos/imageknife' +export { ImageKnifeComponent, ScaleType, ScaleTypeHelper } from '@ohos/imageknife' +export { ImageKnifeDrawFactory } from '@ohos/imageknife' +export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions} from '@ohos/imageknife' +export { ImageKnifeData } from '@ohos/imageknife' +export {IAllCacheInfoCallback,AllCacheInfo,ResourceCacheInfo,MemoryCacheInfo,DataCacheInfo} from '@ohos/imageknife' +export {IParseImage} from '@ohos/imageknife' +export {IDataFetch} from '@ohos/imageknife' +export {ICache} from '@ohos/imageknife' +export { FileTypeUtil } from '@ohos/imageknife' +export { ParseImageUtil } from '@ohos/imageknife' + +/** + * svg parse + */ +export { SVGParseImpl } from '@ohos/imageknife' + +/** + * gif parse + */ +export { GIFParseImpl } from '@ohos/imageknife' +export { GIFFrame } from '@ohos/imageknife' +// 能力增强worker 解析GIF数据 +export { gifHandler } from '@ohos/imageknife' + +// 自定义组件新增 +// 自定义组件绘制生命周期 +export { IDrawLifeCycle } from '@ohos/imageknife' + +// 日志管理 +export { LogUtil } from '@ohos/imageknife' + +// 额外开放初始化ImageKnife的方法 +export {InitImageKnife} from '../ets/pages/InitImageKnife' \ No newline at end of file diff --git a/library/src/main/ets/pages/Index.ets b/library/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..86f8d60 --- /dev/null +++ b/library/src/main/ets/pages/Index.ets @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2023 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 {ImageKnifeGlobal, ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' +import common from '@ohos.app.ability.common' + +@Entry +@Component +struct Index { + + + @State imageOption1:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + @State imageOption2:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + @State imageOption3:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + + build() { + Scroll() { + Column() { + Button('点击加载Resource').onClick(()=>{ + this.imageOption1 = { + loadSrc: $r('app.media.setting'), + // 只要涉及resource加载 在HSP中都要带上context属性 + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption1}).width(300).height(300).backgroundColor(Color.Pink) + Button('点击加载网络图片').onClick(()=>{ + this.imageOption2 = { + loadSrc: 'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB', + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption2}).width(300).height(300).backgroundColor(Color.Pink) + + Button('点击加载本地文件').onClick(()=>{ + getContext(this).createModuleContext('library').resourceManager.getMediaContent($r('app.media.setting').id).then((data:Uint8Array)=>{ + let ctx = ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext; + let path = ctx.filesDir+"/set.jpeg"; + FileUtils.getInstance().writeFile(path,data.buffer) + FileUtils.getInstance().readFilePicAsync(path).then(buffer=>{ + this.imageOption3 = { + loadSrc: path, + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + }) + }) + + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption3}).width(300).height(300).backgroundColor(Color.Pink) + + + + }.width('100%') + + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/library/src/main/ets/pages/InitImageKnife.ets b/library/src/main/ets/pages/InitImageKnife.ets new file mode 100644 index 0000000..b05c84f --- /dev/null +++ b/library/src/main/ets/pages/InitImageKnife.ets @@ -0,0 +1,8 @@ +import common from '@ohos.app.ability.common' +import { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' +import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife' +export class InitImageKnife{ + static init(entryContext:common.UIAbilityContext){ + ImageKnife.with(entryContext); + } +} \ No newline at end of file diff --git a/library/src/main/module.json5 b/library/src/main/module.json5 new file mode 100644 index 0000000..74570f9 --- /dev/null +++ b/library/src/main/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "library", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } +} \ No newline at end of file diff --git a/library/src/main/resources/base/element/color.json b/library/src/main/resources/base/element/color.json new file mode 100644 index 0000000..1bbc9aa --- /dev/null +++ b/library/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/library/src/main/resources/base/element/string.json b/library/src/main/resources/base/element/string.json new file mode 100644 index 0000000..98e1d8a --- /dev/null +++ b/library/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/library/src/main/resources/base/media/icon.png b/library/src/main/resources/base/media/icon.png new file mode 100644 index 0000000..ce307a8 Binary files /dev/null and b/library/src/main/resources/base/media/icon.png differ diff --git a/library/src/main/resources/base/media/setting.jpeg b/library/src/main/resources/base/media/setting.jpeg new file mode 100644 index 0000000..57e67dd Binary files /dev/null and b/library/src/main/resources/base/media/setting.jpeg differ diff --git a/library/src/main/resources/base/profile/main_pages.json b/library/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..1898d94 --- /dev/null +++ b/library/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +}