1.entry adapter stage mode api 9

2.worker adapter stage mode api 9
3.add cropImagePage2.ets test crop pixelMap by fingers

Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
zhoulisheng 2022-07-14 23:39:57 -07:00
parent 4db26e44b8
commit fdbe7d5c5e
54 changed files with 777 additions and 729 deletions

View File

@ -1,6 +1,11 @@
{
"apiType": 'faMode',
"apiType": 'stageMode',
"buildOption": {
"sourceOption": {
"workers": [
"./src/main/ets/pages/workers/worker1.js",
]
}
},
"targets": [
{

View File

@ -1,2 +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').legacyHapTasks
module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks

View File

@ -1,21 +0,0 @@
{
"name": "entry",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@ohos/imageknife": {
"version": "file:../imageknife",
"requires": {
"pako": "^1.0.5"
},
"dependencies": {
"pako": {
"version": "1.0.11",
"resolved": "http://mirrors.tools.huawei.com/npm/pako/-/pako-1.0.11.tgz",
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
}
}
}
}
}

View File

@ -1,14 +1,16 @@
{
"license": "Apache License 2.0",
"devDependencies": {},
"name": "entry",
"ohos": {
"org": "huawei",
"directoryLevel": "module",
"buildTool": "hvigor"
"license":"ISC",
"devDependencies":{},
"name":"entry",
"ohos":{
"org":"huawei",
"directoryLevel":"module",
"buildTool":"hvigor"
},
"version": "1.0.0",
"dependencies": {
"@ohos/imageknife": "file:../imageknife"
"description":"example description",
"repository":{},
"version":"1.0.0",
"dependencies":{
"@ohos/imageknife":"file:../imageknife"
}
}
}

View File

@ -1,140 +0,0 @@
{
"app": {
"vendor": "openharmony",
"bundleName": "cn.openharmony.imageknife",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {
"default": {
"network": {
"cleartextTraffic": true
}
}
},
"module": {
"mainAbility": ".MainAbility",
"deviceType": [
"phone",
"tablet"
],
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:ImageKnife_OHOS",
"formsEnabled": false,
"label": "$string:ImageKnife_OHOS",
"type": "page",
"launchType": "standard"
}
],
"distro": {
"moduleType": "entry",
"installationFree": false,
"deliveryWithInstall": true,
"moduleName": "entry"
},
"package": "cn.openharmony.entry",
"srcPath": "",
"name": ".entry",
"reqPermissions": [
{
"name": "ohos.permission.READ_USER_STORAGE"
},
{
"name": "ohos.permission.INTERNET",
"reason": "Api call",
"usedScene": {
"ability": [
"cn.openharmony.imageknife.MainAbility"
],
"when": "always"
}
},
{
"name": "ohos.permission.KEEP_BACKGROUND_RUNNING"
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "location background",
"usedScene": {
"when": "always",
"ability": [
"cn.openharmony.imageknife.MainAbility"
]
}
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason": "location background",
"usedScene": {
"when": "always",
"ability": [
"cn.openharmony.imageknife.MainAbility"
]
}
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index",
"pages/indexFresco",
"pages/frescoLayerTestCasePage",
"pages/frescoImageTestCasePage",
"pages/frescoRetryTestCasePage",
"pages/basicTestFeatureAbilityPage",
"pages/basicTestFileIOPage",
"pages/basicTestMediaImage",
"pages/basicTestResourceManagerPage",
"pages/storageTestLruCache",
"pages/storageTestDiskLruCache",
"pages/transformTestCasePage",
"pages/pngjTestCasePage",
"pages/testAllTypeImageKnifeComponentPage",
"pages/testAllTypeNativeImagePage",
"pages/loadResourceTestCasePage",
"pages/loadNetworkTestCasePage",
"pages/showErrorholderTestCasePage",
"pages/transformPixelMapPage",
"pages/testGifDontAnimatePage",
"pages/testPreloadPage",
"pages/testImageKnifeOptionChangedPage",
"pages/testImageKnifeOptionChangedPage2",
"pages/compressPage",
"pages/testAllCacheInfoPage",
"pages/testResourceManagerPage",
"pages/testMultiThreadWorkerPage2",
"pages/testImageKnifeOptionChangedPage",
"pages/cropImagePage"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}

View File

@ -0,0 +1,8 @@
import AbilityStage from "@ohos.application.AbilityStage"
import {ImageKnife} from '@ohos/imageknife'
export default class MyAbilityStage extends AbilityStage {
onCreate() {
globalThis.ImageKnife = ImageKnife.with(this.context);
}
}

View File

@ -0,0 +1,7 @@
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}

View File

@ -0,0 +1,42 @@
import Ability from '@ohos.application.Ability'
import {ImageKnife} from '@ohos/imageknife'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
// this.context.resourceManager.getMedia()
// globalThis.ImageKnifeContext = this.context;
// globalThis.ImageKnife = ImageKnife.with(this.context);
// this.context.filesDir
console.log('globalThis.ImageKnife 1 ='+typeof globalThis.ImageKnife)
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
windowStage.setUIContent(this.context, "pages/index", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};

View File

@ -1,146 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import featureAbility from '@ohos.ability.featureAbility';
import {FileUtils} from '@ohos/imageknife'
import {FileTypeUtil} from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager';
import {Base64} from '@ohos/imageknife'
import {PixelMapPack} from '@ohos/imageknife'
import {ParseImageUtil} from '@ohos/imageknife'
@Entry
@Component
struct BasicTestMediaImage {
@State pixelMapPack:PixelMapPack= new PixelMapPack();
build() {
Scroll() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Flex({direction:FlexDirection.Row}){
Button('本地资源jpg')
.onClick(()=>{
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.jpgSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer,(pxielmap)=>{
let jpgPack = new PixelMapPack();
jpgPack.pixelMap = pxielmap;
this.pixelMapPack = jpgPack;
},(err)=>{})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
})
}).margin({left:15}).backgroundColor(Color.Blue)
Button('本地资源png')
.onClick(()=>{
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.pngSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer,(pxielmap)=>{
let pngPack = new PixelMapPack();
pngPack.pixelMap = pxielmap;
this.pixelMapPack = pngPack;
},(err)=>{})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
})
}).margin({left:15}).backgroundColor(Color.Blue)
Button('本地资源bmp')
.onClick(()=>{
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.bmpSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer,(pxielmap)=>{
let bmpPack = new PixelMapPack();
bmpPack.pixelMap = pxielmap;
this.pixelMapPack = bmpPack;
},(err)=>{})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
})
}).margin({left:15}).backgroundColor(Color.Blue)
Button('本地资源webp')
.onClick(()=>{
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.jpgSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer,(pxielmap)=>{
let webpPack = new PixelMapPack();
webpPack.pixelMap = pxielmap;
this.pixelMapPack = webpPack;
},(err)=>{})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
})
}).margin({left:15}).backgroundColor(Color.Blue)
Button('本地资源gif')
.onClick(()=>{
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.gifSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer,(pxielmap)=>{
let gifPack = new PixelMapPack();
gifPack.pixelMap = pxielmap;
this.pixelMapPack = gifPack;
},(err)=>{})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
})
}).margin({left:15}).backgroundColor(Color.Blue)
}
.margin({top:15})
Image(this.pixelMapPack.pixelMap)
.width(300)
.height(300)
.backgroundColor(Color.Pink)
}
}
.width('100%')
.height('100%')
}
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {
return array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset)
}
}

View File

@ -12,12 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import featureAbility from '@ohos.ability.featureAbility';
@Entry
@Component
struct BasicTestFeatureAbilityPage {
@Watch("watchPathChange") @State filePath:string= "查看featureAbility路径";
@Watch("watchPathChange") @State filePath: string = "查看featureAbility路径";
watchPathChange() {
console.log("watchPathChange");
@ -28,30 +28,19 @@ struct BasicTestFeatureAbilityPage {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(this.filePath).fontSize(20)
Button("featureAbility.getContext().getFilesDir()")
.margin({top:20})
.onClick(()=>{
featureAbility.getContext()
.getFilesDir()
.then((data) => {
.margin({ top: 20 })
.onClick(() => {
let data = globalThis.ImageKnife.getImageKnifeContext().filesDir;
console.log("ImageKnife filesPath = " + data)
this.filePath = data
})
.catch((error) => {
console.error('ImageKnife Failed to obtain the filesPath directory. Cause:' + error.message);
})
})
Button("featureAbility.getContext().getCacheDir()")
.margin({top:20})
.onClick(()=>{
featureAbility.getContext().getCacheDir()
.then((data) => {
.margin({ top: 20 })
.onClick(() => {
let data = globalThis.ImageKnife.getImageKnifeContext().cacheDir;
console.log("ImageKnife cachesPath = " + data)
this.filePath = data
})
.catch((error) => {
console.error('ImageKnife Failed to obtain the cachesPath directory. Cause:' + error.message);
})
})
}
}
.width('100%')

View File

@ -12,14 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import featureAbility from '@ohos.ability.featureAbility';
import { FileUtils } from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager';
@Entry
@Component
struct BasicTestFileIOPage {
@Watch('watchPathChange') @State filePath: string= '查看featureAbility路径';
struct basicTestFileIOPage {
@State filePath: string = '查看featureAbility路径';
appFilePath = '';
appCachePath = '';
@State imageFile: string = ''
@ -39,34 +39,27 @@ struct BasicTestFileIOPage {
Button('featureAbility.getContext().getFilesDir()')
.margin({ top: 10 })
.onClick(() => {
featureAbility.getContext()
.getFilesDir()
.then((data) => {
console.log('ImageKnife filesPath = ' + data)
this.filePath = data
this.appFilePath = data;
})
.catch((error) => {
console.error('ImageKnife Failed to obtain the filesPath directory. Cause:' + error.message);
})
let data = globalThis.ImageKnife.getImageKnifeContext().filesDir;
console.log('ImageKnife filesPath = ' + data)
this.filePath = data
this.appFilePath = data;
})
Button('featureAbility.getContext().getCacheDir()')
.margin({ top: 10 })
.onClick(() => {
featureAbility.getContext()
.getCacheDir()
.then((data) => {
console.log('ImageKnife cachesPath = ' + data)
this.filePath = data
this.appCachePath = data
})
.catch((error) => {
console.error('ImageKnife Failed to obtain the cachesPath directory. Cause:' + error.message);
})
let data = globalThis.ImageKnife.getImageKnifeContext().cacheDir;
console.log('ImageKnife cachesPath = ' + data)
this.filePath = data
this.appFilePath = data;
})
Button('files目录创建Folder1和Folder2 验证statSync mkdirSync')
.margin({ top: 10 })
.onClick(() => {
console.log('files目录创建Folder1和Folder2 验证statSync mkdirSync')
FileUtils.getInstance()
.createFolder(this.appFilePath + '/Folder1');
FileUtils.getInstance()
@ -75,59 +68,64 @@ struct BasicTestFileIOPage {
Button('将media资源存入Folder1 验证writeSync mkdirSync createStreamSync')
.margin({ top: 10 })
.onClick(() => {
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.gifSample').id,)
.then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
let arrayBuffer = this.typedArrayToBuffer(data);
FileUtils.getInstance().writeFile(this.appFilePath + '/Folder1/jpgSample.gif', arrayBuffer)
this.imageFile = 'file://' + this.appFilePath + '/Folder1/jpgSample.gif'
})
.catch(err => {
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
})
console.log('将media资源存入Folder1 验证writeSync mkdirSync createStreamSync')
globalThis.ImageKnife.getImageKnifeContext().resourceManager
.getMedia($r('app.media.gifSample').id)
.then(data => {
console.log('result.getMedia')
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length= ' + data.byteLength)
let arrayBuffer = this.typedArrayToBuffer(data);
FileUtils.getInstance().writeFile(this.appFilePath + '/Folder1/jpgSample.gif', arrayBuffer)
this.imageFile = 'file://' + this.appFilePath + '/Folder1/jpgSample.gif'
console.log('Folder1 imaeFile =' + this.imageFile)
})
.catch(err => {
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
})
})
Button('copy:Folder1至Folder2 验证copyFileSync')
.margin({ top: 10 })
.onClick(() => {
console.log('copy:Folder1至Folder2 验证copyFileSync')
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1')
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
FileUtils.getInstance().copyFile(filePath1, filePath2);
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
console.log('Folder2 imaeFile =' + this.imageFile)
})
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('显示空PixelMap')
.margin({ left: 10 })
.onClick(() => {
this.normalPixelMap=true;
this.normalPixelMap = true;
this.normalResource = false;
})
Button('显示RES')
.margin({ left: 10 })
.onClick(() => {
this.normalPixelMap=false;
this.normalPixelMap = false;
this.normalResource = true;
})
Button('显示String')
.margin({ left: 10 })
.onClick(() => {
this.normalPixelMap=false;
this.normalPixelMap = false;
this.normalResource = false;
})
}
Image(this.normalPixelMap?this.imagePixelMap:(this.normalResource? this.imageRes:this.imageFile))
Image(this.normalPixelMap ? this.imagePixelMap : (this.normalResource ? this.imageRes : this.imageFile))
.width(200)
.height(200)
.backgroundColor(Color.Pink)
}
.width('100%')
.height('100%')
}
.width('100%')
.height('100%')
}
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {

View File

@ -0,0 +1,133 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import featureAbility from '@ohos.ability.featureAbility';
import { FileUtils } from '@ohos/imageknife'
import { FileTypeUtil } from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager';
import { Base64 } from '@ohos/imageknife'
import { PixelMapPack } from '@ohos/imageknife'
import { ParseImageUtil } from '@ohos/imageknife'
@Entry
@Component
struct BasicTestMediaImage {
@State pixelMapPack: PixelMapPack = new PixelMapPack();
build() {
Scroll() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Flex({ direction: FlexDirection.Row }) {
Button('本地资源jpg')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.jpgSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
let jpgPack = new PixelMapPack();
jpgPack.pixelMap = pxielmap;
this.pixelMapPack = jpgPack;
}, (err) => {
})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
}).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源png')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.pngSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
let pngPack = new PixelMapPack();
pngPack.pixelMap = pxielmap;
this.pixelMapPack = pngPack;
}, (err) => {
})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
}).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源bmp')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.bmpSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
let bmpPack = new PixelMapPack();
bmpPack.pixelMap = pxielmap;
this.pixelMapPack = bmpPack;
}, (err) => {
})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
}).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源webp')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.jpgSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
let webpPack = new PixelMapPack();
webpPack.pixelMap = pxielmap;
this.pixelMapPack = webpPack;
}, (err) => {
})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
}).margin({ left: 15 }).backgroundColor(Color.Blue)
Button('本地资源gif')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.gifSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let parseImageUtil = new ParseImageUtil();
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
let gifPack = new PixelMapPack();
gifPack.pixelMap = pxielmap;
this.pixelMapPack = gifPack;
}, (err) => {
})
})
.catch(err => {
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
})
}).margin({ left: 15 }).backgroundColor(Color.Blue)
}
.margin({ top: 15 })
Image(this.pixelMapPack.pixelMap)
.width(300)
.height(300)
.backgroundColor(Color.Pink)
}
}
.width('100%')
.height('100%')
}
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {
return array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset)
}
}

View File

@ -31,10 +31,8 @@ struct BasicTestResourceManagerPage {
Button('getMedia解析一张jpg图片')
.margin({ top: 10 })
.onClick(() => {
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.jpgSample')
.id,)
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.jpgSample')
.id,)
.then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
let arrayBuffer = this.typedArrayToBuffer(data);
@ -45,17 +43,14 @@ struct BasicTestResourceManagerPage {
.catch(err => {
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
})
})
})
Button('getMediaBase64解析一张png图片')
.margin({ top: 10 })
.onClick(() => {
resourceManager.getResourceManager()
.then(result => {
result.getMediaBase64($r('app.media.pngSample')
.id)
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMediaBase64($r('app.media.pngSample')
.id)
.then(data => {
console.log('ParseResClientBase64 - 本地加载资源 解析后数据data = ' + data)
console.log('ParseResClientBase64 - 本地加载资源 解析后数据data')
let matchReg = ';base64,';
var firstIndex = data.indexOf(matchReg);
data = data.substring(firstIndex + matchReg.length, data.length)
@ -69,7 +64,6 @@ struct BasicTestResourceManagerPage {
.catch(err => {
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
})
})
})
}

View File

@ -97,7 +97,7 @@ struct CompressPage {
data.push($r('app.media.jpgSample'))
console.info("asasd start compress")
ImageKnife.with()
globalThis.ImageKnife
.compressBuilder()
.load(data)
.ignoreBy(100)
@ -137,7 +137,8 @@ struct CompressPage {
}
}
console.info("asasd start compress")
ImageKnife.with()
globalThis.ImageKnife
.compressBuilder()
.load(data)
.ignoreBy(100)

View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CropImage } from '@ohos/imageknife'
import { CropOptions } from '@ohos/imageknife'
import { Crop } from '@ohos/imageknife'
import { RecourseProvider } from '@ohos/imageknife'
import { PixelMapPack } from '@ohos/imageknife'
import { PixelMapCrop } from '@ohos/imageknife'
import { CropCallback } from '@ohos/imageknife'
import { FileUtils } from '@ohos/imageknife'
@Component
@Entry
export struct CropImagePage2 {
@State options1: PixelMapCrop.Options = new PixelMapCrop.Options();
@State cropTap: boolean = false;
@State pack: PixelMapPack = new PixelMapPack();
@State width: number = 0;
@State height: number = 0;
@State _rotate: number = 0;
@State _scale: number = 1;
private _resource: Resource = $r('app.media.bmpNet');
build() {
Column() {
Button('点击解析图片')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.bmpNet').id)
.then(data => {
let arrayBuffer = FileUtils.getInstance().uint8ArrayToBuffer(data);
let optionx = new PixelMapCrop.Options();
optionx.setWidth(600)
.setHeight(400)
.setCropFunction((err, pixelmap, sx, sy) => {
console.log('PMC setCropFunction callback')
if (err) {
console.error('PMC crop err =' + err)
} else {
let pack1 = new PixelMapPack();
pack1.pixelMap = pixelmap;
this.pack = pack1;
this.width = sx * px2vp(1);
this.height = sy * px2vp(1);
}
})
optionx.loadBuffer(arrayBuffer, () => {
this.options1 = optionx;
})
})
})
PixelMapCrop({ options: this.options1, cropTap: this.cropTap })
Button('点击裁剪图片')
.onClick(() => {
this.cropTap = !this.cropTap;
})
Image(this.pack.pixelMap)
.width(this.width)
.height(this.height)
.objectFit(ImageFit.Contain)
.rotate({
z: 1,
centerX: this.width / 2,
centerY: this.height / 2,
angle: this._rotate
})
.scale({ x: this._scale, y: this._scale, z: 1.0 })
.gesture(GestureGroup(GestureMode.Parallel,
RotationGesture({ fingers: 2 }).onActionUpdate(event => {
this._rotate = event.angle;
}), PinchGesture({ fingers: 2 }).onActionUpdate(event => {
this._scale = event.scale;
})))
}
.backgroundColor(Color.Brown)
.width('100%')
.height('100%')
}
}

View File

@ -22,8 +22,6 @@ import {RoundedCornersTransformation} from '@ohos/imageknife'
struct FrescoImageTestCasePage {
@State progresshint:string = "输出加载百分比回调信息"
@State imageKnifeOption1: ImageKnifeOption =
{
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",

View File

@ -13,13 +13,14 @@
* limitations under the License.
*/
import router from '@system.router';
import {Pngj} from '@ohos/imageknife'
@Entry
@Component
struct Index {
@State hint1:string = '启用网络模拟加载替换网络加载'
struct IndexFunctionDemo {
@State hint1: string = '启用网络模拟加载替换网络加载'
build() {
Scroll() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
@ -148,12 +149,20 @@ struct Index {
console.log("pages/pngjTestCasePage 页面跳转")
router.push({ uri: "pages/pngjTestCasePage" });
}).margin({ top: 15 })
Button("测试图片的裁剪")
.onClick(() => {
console.log("pages/cropImagePage 页面跳转")
router.push({ uri: "pages/cropImagePage" });
}).margin({ top: 15 })
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button("测试图片的裁剪")
.onClick(() => {
console.log("pages/cropImagePage 页面跳转")
router.push({ uri: "pages/cropImagePage" });
}).margin({ top: 15 })
Button("测试图片的裁剪2")
.onClick(() => {
console.log("pages/cropImagePage2 页面跳转")
router.push({ uri: "pages/cropImagePage2" });
}).margin({ top: 15 })
}.width('100%')
.height(60).backgroundColor(Color.Pink)
}
}
.width('100%')
@ -164,12 +173,6 @@ struct Index {
}
onBackPress() {
let cache = ImageKnife.getMemoryCache();
cache.print()
}
}
var ImageKnife;
var defaultTemp = globalThis.exports.default
if (defaultTemp != undefined) {
ImageKnife = defaultTemp.data.imageKnife;
}

View File

@ -22,27 +22,19 @@ struct IndexFresco {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button("测试控件隐藏与展示和动画")
.onClick(() => {
router.push({ uri: "pages/frescoLayerTestCasePage" });
}).margin({ top: 15 })
router.push({ uri: "pages/frescoLayerTestCasePage" });
}).margin({ top: 15 })
Button("测试自定义控件FrescoImage的加载百分比")
.onClick(() => {
router.push({ uri: "pages/frescoImageTestCasePage" });
}).margin({ top: 15 })
router.push({ uri: "pages/frescoImageTestCasePage" });
}).margin({ top: 15 })
Button("测试自定义控件FrescoImage重试Retry")
.onClick(() => {
router.push({ uri: "pages/frescoRetryTestCasePage" });
}).margin({ top: 15 })
router.push({ uri: "pages/frescoRetryTestCasePage" });
}).margin({ top: 15 })
}
}
.width('100%')
.height('100%')
}
}
}

View File

@ -13,20 +13,33 @@
* limitations under the License.
*/
import router from '@system.router';
import {Pngj} from '@ohos/imageknife'
import { Pngj } from '@ohos/imageknife'
import {
RESOLUTION_UNITS,
insertMetadata,
readMetadata,
writeMetadata,
textEncode,
textDecode,
extractChunks,
encodeChunks
} from '@ohos/imageknife'
import resourceManager from '@ohos.resourceManager';
import {FileUtils} from '@ohos/imageknife'
import { FileUtils } from '@ohos/imageknife'
import featureability from '@ohos.ability.featureAbility'
import ArkWorker from '@ohos.worker'
@Entry
@Component
struct PngjTestCasePage {
pngSource: ArrayBuffer = new ArrayBuffer(0);
pngSource: ArrayBuffer = new ArrayBuffer(0);
rootFolder: string = '';
@State hint1: string = 'readPngImageInfo内容展示'
@State hint2: string = 'readPngImage内容展示'
@State hint3: string = 'writePngWithString内容展示'
@State hint4: string = 'writePngWithString内容展示'
@State hint5: string = '测试readMetadata'
@State hint6: string = '测试writeMetadata'
build() {
Scroll() {
@ -36,25 +49,15 @@ struct PngjTestCasePage {
Button('点击获取Png图片buffer').fontSize(20)
.onClick(() => {
featureability.getContext()
.getFilesDir()
.then((data) => {
this.rootFolder = data;
})
.catch((err) => {
console.log('点击获取Png图片buffer 路径获取失败 err:' + err)
})
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir;
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.Tomato').id)
.then(data => {
this.pngSource = FileUtils.getInstance().uint8ArrayToBuffer(data);
})
.catch(err => {
console.log('点击获取Png图片buffer err=' + err)
})
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.Tomato').id)
.then(data => {
this.pngSource = FileUtils.getInstance().uint8ArrayToBuffer(data);
})
.catch(err => {
console.log('点击获取Png图片buffer err=' + err)
})
})
@ -103,6 +106,7 @@ struct PngjTestCasePage {
}).margin({ top: 5, left: 10 })
}.width('100%')
.height(60).backgroundColor(Color.Pink)
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('测试readPngImageInfo')
.onClick(() => {
@ -114,7 +118,10 @@ struct PngjTestCasePage {
Button('测试readPngImageAsync')
.onClick(() => {
let pngj = new Pngj();
let worker = new ArkWorker.Worker('workers/worker1.js', { type: 'classic', name: 'readPngImageAsync'})
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
type: 'classic',
name: 'readPngImageAsync'
})
pngj.readPngImageAsync(worker, this.pngSource, (sender, value) => {
this.pngSource = sender
this.hint2 = 'img with=' + value.width + ' img height=' + value.height
@ -124,7 +131,10 @@ struct PngjTestCasePage {
Button('测试writePngWithStringAsync')
.onClick(() => {
let pngj = new Pngj();
let worker = new ArkWorker.Worker('workers/worker1.js', { type: 'classic', name: 'writePngWithStringAsync'})
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
type: 'classic',
name: 'writePngWithStringAsync'
})
pngj.writePngWithStringAsync(worker, 'hello world', this.pngSource, (sender, value) => {
this.pngSource = sender
FileUtils.getInstance().createFileProcess(
@ -138,7 +148,10 @@ struct PngjTestCasePage {
Button('测试writePngAsync')
.onClick(() => {
let pngj = new Pngj();
let worker = new ArkWorker.Worker('workers/worker1.js', { type: 'classic', name: 'writePngAsync'})
let worker = new ArkWorker.Worker('entry/ets/pages/workers/worker1.js', {
type: 'classic',
name: 'writePngAsync'
})
pngj.writePngAsync(worker, this.pngSource, (sender, value) => {
this.pngSource = sender
FileUtils.getInstance().createFileProcess(
@ -152,6 +165,38 @@ struct PngjTestCasePage {
}.width('100%')
.height(60).backgroundColor(Color.Pink)
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('测试readMetadata')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext()
.resourceManagergetMedia($r('app.media.pngSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
let metadata = readMetadata(arrayBuffer);
console.log("readMetadata metadata=" + JSON.stringify(metadata))
this.hint5 = JSON.stringify(metadata);
})
.catch(err => {
console.log('测试readMetadata err=' + err)
})
}).margin({ top: 5, left: 10 })
Button('测试writeMetadata')
.onClick(() => {
globalThis.ImageKnife.getImageKnifeContext()
.resourceManagergetMedia($r('app.media.pngSample').id)
.then(data => {
let arrayBuffer = this.typedArrayToBuffer(data);
// let pngBuffer = writeMetadata(arrayBuffer);
// console.log("writeMetadata metadata="+JSON.stringify(metadata))
// this.hint5 = JSON.stringify(metadata);
})
.catch(err => {
console.log('测试writeMetadata err=' + err)
})
}).margin({ top: 5, left: 10 })
}.width('100%')
.height(60).backgroundColor(Color.Pink)
Text(this.hint1)
.width('100%')
.height(120)
@ -165,9 +210,9 @@ struct PngjTestCasePage {
.width('100%')
.height(120)
}
.width('100%')
.height('100%')
}
.width('100%')
.height('100%')
}
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {

View File

@ -53,12 +53,12 @@ struct StorageTestDiskLruCache {
.backgroundColor(Color.Blue)
Button("替换ImageKnife默认DiskLruCache并设置大小1M")
.onClick(() => {
DiskImageKnife.replaceDiskLruCache(1 * 1024 * 1024)
globalThis.ImageKnife.replaceDiskLruCache(1 * 1024 * 1024)
}).margin({top:15, bottom:15})
Button("替换ImageKnife默认DiskLruCache并设置大小30M")
.onClick(() => {
DiskImageKnife.replaceDiskLruCache(30 * 1024 * 1024)
globalThis.ImageKnife.replaceDiskLruCache(30 * 1024 * 1024)
}).margin({top:15, bottom:15})
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
@ -170,19 +170,24 @@ struct StorageTestDiskLruCache {
request.addAllCacheInfoCallback(this.imageKnifeOption.allCacheInfoCallback)
}
DiskImageKnife.call(request);
globalThis.ImageKnife.call(request);
}
imageKnifeChangeSource(data:ImageKnifeData) {
this.imageKnifeSpecialFixed(data);
//查看mImageKnife中的DiskLruCache
let disk = DiskImageKnife.getDiskMemoryCache();
let showDisk = ''
disk.foreachDiskLruCache((value, key, map) => {
showDisk += "key=" + key + "&value=" + value;
})
this.logText = "日志结果:" + showDisk;
// 由于异步写入可能读取disklrucache的时候还没删成功为了保证成功删除这里使用了延时
setTimeout(() => {
//查看mImageKnife中的DiskLruCache
let disk = globalThis.ImageKnife.getDiskMemoryCache();
let showDisk = ''
disk.foreachDiskLruCache((value, key, map) => {
showDisk += "key=" + key + "&value=" + value;
})
this.logText = "日志结果:" + showDisk;
}, 2000)
}
imageKnifeSpecialFixed(data:ImageKnifeData) {
@ -226,7 +231,7 @@ struct StorageTestDiskLruCache {
console.log("ImageKnife占位图输出=String 拥有上一个图片类型 上一个是SVG")
this.normalPixelMap = false;
this.normalResource = false;
let firstIndex = (data.imageKnifeValue as string).indexOf(DiskImageKnife.getSvgAndGifFolder());
let firstIndex = (data.imageKnifeValue as string).indexOf(globalThis.ImageKnife.getSvgAndGifFolder());
console.log("firstIndex=" + firstIndex);
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
console.log("suffix =" + suffix);
@ -238,7 +243,7 @@ struct StorageTestDiskLruCache {
this.normalPixelMap = false;
this.normalResource = false;
let firstIndex = (data.imageKnifeValue as string).indexOf(DiskImageKnife.getSvgAndGifFolder());
let firstIndex = (data.imageKnifeValue as string).indexOf(globalThis.ImageKnife.getSvgAndGifFolder());
console.log("firstIndex=" + firstIndex);
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
console.log("suffix =" + suffix);
@ -280,7 +285,7 @@ struct StorageTestDiskLruCache {
console.log("ImageKnife占位图输出=String 没有上一个图片类型")
this.normalPixelMap = false;
this.normalResource = false;
let firstIndex = (data.imageKnifeValue as string).indexOf(DiskImageKnife.getSvgAndGifFolder());
let firstIndex = (data.imageKnifeValue as string).indexOf(globalThis.ImageKnife.getSvgAndGifFolder());
console.log("firstIndex=" + firstIndex);
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
console.log("suffix =" + suffix);
@ -318,4 +323,3 @@ struct StorageTestDiskLruCache {
}
}
var DiskImageKnife = globalThis.exports.default.data.imageKnife

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import featureAbility from '@ohos.ability.featureAbility';
import {LruCache} from '@ohos/imageknife'
function getRandomInt(min, max) {

View File

@ -207,4 +207,4 @@ struct TestAllCacheInfoPage {
}
var ImageKnife = globalThis.exports.default.data.imageKnife
var ImageKnife = globalThis.ImageKnife

View File

@ -31,17 +31,17 @@ struct TestGifDontAnimatePage {
build() {
Scroll() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Flex({direction:FlexDirection.Row}){
Column() {
Flex({ direction: FlexDirection.Row }) {
Button('本地资源gif')
.onClick(()=>{
this.imageKnifeOption1 = {
loadSrc: $r('app.media.gifSample'),
size: { width: 300, height: 300 },
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
margin:{left:15,top:15,right:15,bottom:15}
}
.onClick(() => {
this.imageKnifeOption1 = {
loadSrc: $r('app.media.gifSample'),
size: { width: 300, height: 300 },
placeholderSrc: $r('app.media.icon_loading'),
errorholderSrc: $r('app.media.icon_failed'),
margin: { left: 15, top: 15, right: 15, bottom: 15 }
}
}).margin({left:15}).backgroundColor(Color.Grey)
Button('本地资源gif静态')
@ -95,5 +95,4 @@ struct TestGifDontAnimatePage {
}
}
var ImageKnife = globalThis.exports.default.data.imageKnife
var ImageKnife = globalThis.ImageKnife

View File

@ -105,4 +105,3 @@ struct TestImageKnifeOptionChangedPage2 {
}
var ImageKnife = globalThis.exports.default.data.imageKnife

View File

@ -23,7 +23,10 @@ struct TestMultiThreadWorkerPage2 {
Button("创建Worker向子线程发送携带Arraybuffer数据")
.margin({ top: 20 })
.onClick(() => {
let worker = new ArkWorker.Worker("workers/worker1.js", { type: "classic", name: "zhangsan" })
let worker = new ArkWorker.Worker("entry/ets/pages/workers/worker1.js", {
type: "classic",
name: "zhangsan"
})
worker.onerror = function (data) {
console.info("worker:: receive onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno);
}

View File

@ -15,7 +15,7 @@
import {ImageKnifeComponent} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife'
import {RequestOption} from '@ohos/imageknife'
import {RotateImageTransformation} from '@ohos/imageknife'
@Entry
@Component
@ -72,18 +72,18 @@ struct TestPreloadPage {
build() {
Scroll() {
Flex({ direction: FlexDirection.Column }) {
Flex({ direction: FlexDirection.Column }) {
Column() {
Column() {
Flex({ direction: FlexDirection.Row }) {
Button('预加载本地资源gif')
.onClick(() => {
let request = new RequestOption();
request.load($r('app.media.gifSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源gif 出现错误! err=' + err)
} else {
let request = new RequestOption();
request.load($r('app.media.gifSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源gif 出现错误! err=' + err)
} else {
console.log('预加载本地资源gif成功! imageKnifedata=' + JSON.stringify(data))
}
return false;
@ -216,17 +216,17 @@ struct TestPreloadPage {
}
Flex({ direction: FlexDirection.Column }) {
Column() {
Flex({ direction: FlexDirection.Row }) {
Button('预加载本地资源svg')
.onClick(() => {
let request = new RequestOption();
request.load($r('app.media.svgSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源svg 出现错误! err=' + err)
} else {
let request = new RequestOption();
request.load($r('app.media.svgSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源svg 出现错误! err=' + err)
} else {
console.log('预加载本地资源svg成功! imageKnifedata=' + JSON.stringify(data))
}
return false;
@ -296,17 +296,17 @@ struct TestPreloadPage {
}
Flex({ direction: FlexDirection.Column }) {
Column() {
Flex({ direction: FlexDirection.Row }) {
Button('预加载本地资源webp')
.onClick(() => {
let request = new RequestOption();
request.load($r('app.media.jpgSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源webp 出现错误! err=' + err)
} else {
let request = new RequestOption();
request.load($r('app.media.jpgSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源webp 出现错误! err=' + err)
} else {
console.log('预加载本地资源webp成功! imageKnifedata=' + JSON.stringify(data))
}
return false;
@ -374,17 +374,17 @@ struct TestPreloadPage {
}
Flex({ direction: FlexDirection.Column }) {
Column() {
Flex({ direction: FlexDirection.Row }) {
Button('预加载本地资源bmp')
.onClick(() => {
let request = new RequestOption();
request.load($r('app.media.bmpSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源bmp 出现错误! err=' + err)
} else {
let request = new RequestOption();
request.load($r('app.media.bmpSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源bmp 出现错误! err=' + err)
} else {
console.log('预加载本地资源bmp成功! imageKnifedata=' + JSON.stringify(data))
}
return false;
@ -452,17 +452,17 @@ struct TestPreloadPage {
}
Flex({ direction: FlexDirection.Column }) {
Column() {
Flex({ direction: FlexDirection.Row }) {
Button('预加载本地资源png')
.onClick(() => {
let request = new RequestOption();
request.load($r('app.media.pngSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源png 出现错误! err=' + err)
} else {
let request = new RequestOption();
request.load($r('app.media.pngSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源png 出现错误! err=' + err)
} else {
console.log('预加载本地资源png成功! imageKnifedata=' + JSON.stringify(data))
}
return false;
@ -530,17 +530,17 @@ struct TestPreloadPage {
}
Flex({ direction: FlexDirection.Column }) {
Column() {
Flex({ direction: FlexDirection.Row }) {
Button('预加载本地资源jpg')
.onClick(() => {
let request = new RequestOption();
request.load($r('app.media.jpgSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源jpg 出现错误! err=' + err)
} else {
let request = new RequestOption();
request.load($r('app.media.jpgSample'))
.setImageViewSize({ width: 300, height: 300 })
.addListener((err, data) => {
if (err && err.length > 0) {
console.log('预加载本地资源jpg 出现错误! err=' + err)
} else {
console.log('预加载本地资源jpg成功! imageKnifedata=' + JSON.stringify(data))
}
return false;
@ -608,9 +608,11 @@ struct TestPreloadPage {
}
}
}
.width('100%')
.height('100%')
}
aboutToAppear() {
@ -619,4 +621,4 @@ struct TestPreloadPage {
}
var ImageKnife = globalThis.exports.default.data.imageKnife
var ImageKnife = globalThis.ImageKnife

View File

@ -36,9 +36,7 @@ struct TestResourceManagerPage {
.height(300)
Button("点击执行ResourceManager的Base64")
.onClick(()=>{
resourceManager.getResourceManager()
.then(result => {
result.getMediaBase64($r('app.media.jpgSample').id)
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMediaBase64($r('app.media.jpgSample').id)
.then(data => {
console.log("jpgSample data=" + data)
let matchUseLess = ";base64,";
@ -55,15 +53,11 @@ struct TestResourceManagerPage {
this.imageKnifeData = newImageKnifeData;
})
})
})
Button("点击执行ResourceManager的非Base64")
.margin({top:25})
.onClick(()=>{
resourceManager.getResourceManager()
.then(result => {
result.getMedia($r('app.media.pngSample').id)
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.pngSample').id)
.then(data => {
console.log("arrayBuffer data=" + data)
let fileTypeUtil = new FileTypeUtil();
@ -73,8 +67,6 @@ struct TestResourceManagerPage {
newImageKnifeData.imageKnifeType = typeValue
this.imageKnifeData = newImageKnifeData;
})
})
})
}
}

View File

@ -12,17 +12,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {RequestOption} from '@ohos/imageknife'
import {CropCircleWithBorderTransformation} from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation'
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 { RequestOption } from '@ohos/imageknife'
import { CropCircleTransformation } from '@ohos/imageknife'
import { RoundedCornersTransformation } from '@ohos/imageknife'
import {
CropCircleWithBorderTransformation
} from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation'
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'
@ -874,4 +878,4 @@ struct TransformPixelMapPage {
}
}
var ImageKnife = globalThis.exports.default.data.imageKnife
var ImageKnife = globalThis.ImageKnife

View File

@ -13,9 +13,16 @@
* limitations under the License.
*/
import arkWorker from '@ohos.worker';
import {handler} from '@ohos/imageknife/src/main/ets/components/imageknife/pngj/PngWork'
arkWorker.parentPort.onmessage = handler

View File

@ -0,0 +1,40 @@
{
"module": {
"name": "entry",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"requestPermissions": [{"name": "ohos.permission.INTERNET"}],
"uiSyntax": "ets",
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:test_color",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
}
}

View File

@ -1,5 +1,18 @@
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "ImageKnife_OHOS",
"value": "ImageKnife_OHOS"

View File

@ -0,0 +1,33 @@
{
"src": [
"pages/index",
"pages/indexFresco",
"pages/frescoLayerTestCasePage",
"pages/frescoImageTestCasePage",
"pages/frescoRetryTestCasePage",
"pages/basicTestFeatureAbilityPage",
"pages/basicTestFileIOPage",
"pages/basicTestMediaImage",
"pages/basicTestResourceManagerPage",
"pages/storageTestLruCache",
"pages/storageTestDiskLruCache",
"pages/transformTestCasePage",
"pages/pngjTestCasePage",
"pages/testAllTypeImageKnifeComponentPage",
"pages/testAllTypeNativeImagePage",
"pages/loadResourceTestCasePage",
"pages/loadNetworkTestCasePage",
"pages/showErrorholderTestCasePage",
"pages/transformPixelMapPage",
"pages/testGifDontAnimatePage",
"pages/testPreloadPage",
"pages/testImageKnifeOptionChangedPage",
"pages/testImageKnifeOptionChangedPage2",
"pages/compressPage",
"pages/testAllCacheInfoPage",
"pages/testResourceManagerPage",
"pages/testMultiThreadWorkerPage2",
"pages/cropImagePage",
"pages/cropImagePage2"
]
}

View File

@ -1,68 +0,0 @@
{
"app": {
"bundleName": "com.example.imageknifegiteepro",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.entry_test",
"name": ".entry_test",
"mainAbility": ".TestAbility",
"srcPath": "",
"deviceType": [
"phone",
"tablet"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry_test",
"moduleType": "feature",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "TestAbility",
"name": ".TestAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_TestAbility",
"formsEnabled": false,
"label": "$string:entry_TestAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}

View File

@ -0,0 +1,7 @@
import AbilityStage from "@ohos.application.AbilityStage"
export default class TestAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] TestAbilityStage onCreate")
}
}

View File

@ -0,0 +1,39 @@
import Ability from '@ohos.application.Ability'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from 'hypium/index'
import testsuite from '../test/List.test'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
console.log('TestAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate')
windowStage.setUIContent(this.context, 'TestAbility/pages/index', null)
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy')
}
onForeground() {
console.log('TestAbility onForeground')
}
onBackground() {
console.log('TestAbility onBackground')
}
};

View File

@ -1,32 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from 'hypium/index'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('Application onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info('Application onDestroy')
},
}

View File

@ -1,18 +1,4 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router';
import router from '@ohos.router';
@Entry
@Component
@ -20,7 +6,6 @@ struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {

View File

@ -1,17 +1,3 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
@ -20,25 +6,24 @@ var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package'
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log('onAbilityCreateCallback');
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info('addAbilityMonitorCallback : ' + JSON.stringify(err))
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
@ -46,21 +31,20 @@ export default class OpenHarmonyTestRunner implements TestRunner {
}
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
console.info("OpenHarmonyTestRunner OnPrepare ")
}
onRun() {
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
@ -69,9 +53,6 @@ export default class OpenHarmonyTestRunner implements TestRunner {
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun call abilityDelegator.getAppContext')
var context = abilityDelegator.getAppContext()
console.info('getAppContext : ' + JSON.stringify(context))
console.info('OpenHarmonyTestRunner onRun end')
}
};

View File

@ -1,17 +1,3 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index'
export default function abilityTest() {

View File

@ -1,17 +1,3 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import abilityTest from './Ability.test'
export default function testsuite() {

View File

@ -0,0 +1,37 @@
{
"module": {
"name": "entry_test",
"type": "feature",
"srcEntrance": "./ets/TestAbility/TestAbility.ts",
"description": "$string:entry_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "TestAbility",
"srcEntrance": "./ets/TestAbility/TestAbility.ts",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"visible": true,
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}

View File

@ -1,12 +1,16 @@
{
"string": [
{
"name": "description_TestAbility",
"value": "eTS_Empty Ability"
"name": "entry_test_desc",
"value": "i am an entry for tv"
},
{
"name": "entry_TestAbility",
"value": "entry_TestAbility"
"name": "TestAbility_desc",
"value": "the tv entry test ability"
},
{
"name": "TestAbility_label",
"value": "tvBase"
}
]
}

View File

@ -0,0 +1,5 @@
{
"src": [
"TestAbility/pages/index"
]
}