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:
parent
4db26e44b8
commit
fdbe7d5c5e
|
@ -1,6 +1,11 @@
|
||||||
{
|
{
|
||||||
"apiType": 'faMode',
|
"apiType": 'stageMode',
|
||||||
"buildOption": {
|
"buildOption": {
|
||||||
|
"sourceOption": {
|
||||||
|
"workers": [
|
||||||
|
"./src/main/ets/pages/workers/worker1.js",
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
// 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
|
||||||
|
|
|
@ -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=="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +1,16 @@
|
||||||
{
|
{
|
||||||
"license": "Apache License 2.0",
|
"license":"ISC",
|
||||||
"devDependencies": {},
|
"devDependencies":{},
|
||||||
"name": "entry",
|
"name":"entry",
|
||||||
"ohos": {
|
"ohos":{
|
||||||
"org": "huawei",
|
"org":"huawei",
|
||||||
"directoryLevel": "module",
|
"directoryLevel":"module",
|
||||||
"buildTool": "hvigor"
|
"buildTool":"hvigor"
|
||||||
},
|
},
|
||||||
"version": "1.0.0",
|
"description":"example description",
|
||||||
"dependencies": {
|
"repository":{},
|
||||||
"@ohos/imageknife": "file:../imageknife"
|
"version":"1.0.0",
|
||||||
|
"dependencies":{
|
||||||
|
"@ohos/imageknife":"file:../imageknife"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import AbilityStage from "@ohos.application.AbilityStage"
|
||||||
|
|
||||||
|
export default class MyAbilityStage extends AbilityStage {
|
||||||
|
onCreate() {
|
||||||
|
console.log("[Demo] MyAbilityStage onCreate")
|
||||||
|
}
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
||||||
|
};
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,12 +12,12 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import featureAbility from '@ohos.ability.featureAbility';
|
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct BasicTestFeatureAbilityPage {
|
struct BasicTestFeatureAbilityPage {
|
||||||
@Watch("watchPathChange") @State filePath:string= "查看featureAbility路径";
|
@Watch("watchPathChange") @State filePath: string = "查看featureAbility路径";
|
||||||
|
|
||||||
watchPathChange() {
|
watchPathChange() {
|
||||||
console.log("watchPathChange");
|
console.log("watchPathChange");
|
||||||
|
@ -28,30 +28,19 @@ struct BasicTestFeatureAbilityPage {
|
||||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
Text(this.filePath).fontSize(20)
|
Text(this.filePath).fontSize(20)
|
||||||
Button("featureAbility.getContext().getFilesDir()")
|
Button("featureAbility.getContext().getFilesDir()")
|
||||||
.margin({top:20})
|
.margin({ top: 20 })
|
||||||
.onClick(()=>{
|
.onClick(() => {
|
||||||
featureAbility.getContext()
|
let data = globalThis.ImageKnife.getImageKnifeContext().filesDir;
|
||||||
.getFilesDir()
|
|
||||||
.then((data) => {
|
|
||||||
console.log("ImageKnife filesPath = " + data)
|
console.log("ImageKnife filesPath = " + data)
|
||||||
this.filePath = data
|
this.filePath = data
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
|
||||||
console.error('ImageKnife Failed to obtain the filesPath directory. Cause:' + error.message);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Button("featureAbility.getContext().getCacheDir()")
|
Button("featureAbility.getContext().getCacheDir()")
|
||||||
.margin({top:20})
|
.margin({ top: 20 })
|
||||||
.onClick(()=>{
|
.onClick(() => {
|
||||||
featureAbility.getContext().getCacheDir()
|
let data = globalThis.ImageKnife.getImageKnifeContext().cacheDir;
|
||||||
.then((data) => {
|
|
||||||
console.log("ImageKnife cachesPath = " + data)
|
console.log("ImageKnife cachesPath = " + data)
|
||||||
this.filePath = data
|
this.filePath = data
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
|
||||||
console.error('ImageKnife Failed to obtain the cachesPath directory. Cause:' + error.message);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
|
@ -12,14 +12,14 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import featureAbility from '@ohos.ability.featureAbility';
|
|
||||||
import { FileUtils } from '@ohos/imageknife'
|
import { FileUtils } from '@ohos/imageknife'
|
||||||
import resourceManager from '@ohos.resourceManager';
|
import resourceManager from '@ohos.resourceManager';
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct BasicTestFileIOPage {
|
struct basicTestFileIOPage {
|
||||||
@Watch('watchPathChange') @State filePath: string= '查看featureAbility路径';
|
@State filePath: string = '查看featureAbility路径';
|
||||||
appFilePath = '';
|
appFilePath = '';
|
||||||
appCachePath = '';
|
appCachePath = '';
|
||||||
@State imageFile: string = ''
|
@State imageFile: string = ''
|
||||||
|
@ -39,34 +39,27 @@ struct BasicTestFileIOPage {
|
||||||
Button('featureAbility.getContext().getFilesDir()')
|
Button('featureAbility.getContext().getFilesDir()')
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
featureAbility.getContext()
|
|
||||||
.getFilesDir()
|
let data = globalThis.ImageKnife.getImageKnifeContext().filesDir;
|
||||||
.then((data) => {
|
console.log('ImageKnife filesPath = ' + data)
|
||||||
console.log('ImageKnife filesPath = ' + data)
|
this.filePath = data
|
||||||
this.filePath = data
|
this.appFilePath = data;
|
||||||
this.appFilePath = data;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('ImageKnife Failed to obtain the filesPath directory. Cause:' + error.message);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
Button('featureAbility.getContext().getCacheDir()')
|
Button('featureAbility.getContext().getCacheDir()')
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
featureAbility.getContext()
|
|
||||||
.getCacheDir()
|
let data = globalThis.ImageKnife.getImageKnifeContext().cacheDir;
|
||||||
.then((data) => {
|
console.log('ImageKnife cachesPath = ' + data)
|
||||||
console.log('ImageKnife cachesPath = ' + data)
|
this.filePath = data
|
||||||
this.filePath = data
|
this.appFilePath = data;
|
||||||
this.appCachePath = data
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('ImageKnife Failed to obtain the cachesPath directory. Cause:' + error.message);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
Button('files目录创建Folder1和Folder2 验证statSync mkdirSync')
|
Button('files目录创建Folder1和Folder2 验证statSync mkdirSync')
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
|
console.log('files目录创建Folder1和Folder2 验证statSync mkdirSync')
|
||||||
FileUtils.getInstance()
|
FileUtils.getInstance()
|
||||||
.createFolder(this.appFilePath + '/Folder1');
|
.createFolder(this.appFilePath + '/Folder1');
|
||||||
FileUtils.getInstance()
|
FileUtils.getInstance()
|
||||||
|
@ -75,59 +68,64 @@ struct BasicTestFileIOPage {
|
||||||
Button('将media资源存入Folder1 验证writeSync mkdirSync createStreamSync')
|
Button('将media资源存入Folder1 验证writeSync mkdirSync createStreamSync')
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
resourceManager.getResourceManager()
|
console.log('将media资源存入Folder1 验证writeSync mkdirSync createStreamSync')
|
||||||
.then(result => {
|
globalThis.ImageKnife.getImageKnifeContext().resourceManager
|
||||||
result.getMedia($r('app.media.gifSample').id,)
|
.getMedia($r('app.media.gifSample').id)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
|
console.log('result.getMedia')
|
||||||
let arrayBuffer = this.typedArrayToBuffer(data);
|
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data length= ' + data.byteLength)
|
||||||
FileUtils.getInstance().writeFile(this.appFilePath + '/Folder1/jpgSample.gif', arrayBuffer)
|
let arrayBuffer = this.typedArrayToBuffer(data);
|
||||||
this.imageFile = 'file://' + this.appFilePath + '/Folder1/jpgSample.gif'
|
FileUtils.getInstance().writeFile(this.appFilePath + '/Folder1/jpgSample.gif', arrayBuffer)
|
||||||
})
|
this.imageFile = 'file://' + this.appFilePath + '/Folder1/jpgSample.gif'
|
||||||
.catch(err => {
|
console.log('Folder1 imaeFile =' + this.imageFile)
|
||||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
})
|
||||||
})
|
.catch(err => {
|
||||||
|
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Button('copy:Folder1至Folder2, 验证copyFileSync')
|
Button('copy:Folder1至Folder2, 验证copyFileSync')
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
|
console.log('copy:Folder1至Folder2, 验证copyFileSync')
|
||||||
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
|
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
|
||||||
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
|
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
|
||||||
|
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1')
|
||||||
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
|
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
|
||||||
FileUtils.getInstance().copyFile(filePath1, filePath2);
|
FileUtils.getInstance().copyFile(filePath1, filePath2);
|
||||||
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
|
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
|
||||||
|
console.log('Folder2 imaeFile =' + this.imageFile)
|
||||||
})
|
})
|
||||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
Button('显示空PixelMap')
|
Button('显示空PixelMap')
|
||||||
.margin({ left: 10 })
|
.margin({ left: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
this.normalPixelMap=true;
|
this.normalPixelMap = true;
|
||||||
this.normalResource = false;
|
this.normalResource = false;
|
||||||
})
|
})
|
||||||
Button('显示RES')
|
Button('显示RES')
|
||||||
.margin({ left: 10 })
|
.margin({ left: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
this.normalPixelMap=false;
|
this.normalPixelMap = false;
|
||||||
this.normalResource = true;
|
this.normalResource = true;
|
||||||
})
|
})
|
||||||
Button('显示String')
|
Button('显示String')
|
||||||
.margin({ left: 10 })
|
.margin({ left: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
this.normalPixelMap=false;
|
this.normalPixelMap = false;
|
||||||
this.normalResource = 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)
|
.width(200)
|
||||||
.height(200)
|
.height(200)
|
||||||
.backgroundColor(Color.Pink)
|
.backgroundColor(Color.Pink)
|
||||||
}
|
}
|
||||||
|
.width('100%')
|
||||||
|
.height('100%')
|
||||||
}
|
}
|
||||||
.width('100%')
|
|
||||||
.height('100%')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {
|
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,10 +31,8 @@ struct BasicTestResourceManagerPage {
|
||||||
Button('getMedia解析一张jpg图片')
|
Button('getMedia解析一张jpg图片')
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
resourceManager.getResourceManager()
|
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.jpgSample')
|
||||||
.then(result => {
|
.id,)
|
||||||
result.getMedia($r('app.media.jpgSample')
|
|
||||||
.id,)
|
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
|
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
|
||||||
let arrayBuffer = this.typedArrayToBuffer(data);
|
let arrayBuffer = this.typedArrayToBuffer(data);
|
||||||
|
@ -45,17 +43,14 @@ struct BasicTestResourceManagerPage {
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
Button('getMediaBase64解析一张png图片')
|
Button('getMediaBase64解析一张png图片')
|
||||||
.margin({ top: 10 })
|
.margin({ top: 10 })
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
resourceManager.getResourceManager()
|
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMediaBase64($r('app.media.pngSample')
|
||||||
.then(result => {
|
.id)
|
||||||
result.getMediaBase64($r('app.media.pngSample')
|
|
||||||
.id)
|
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log('ParseResClientBase64 - 本地加载资源 解析后数据data = ' + data)
|
console.log('ParseResClientBase64 - 本地加载资源 解析后数据data')
|
||||||
let matchReg = ';base64,';
|
let matchReg = ';base64,';
|
||||||
var firstIndex = data.indexOf(matchReg);
|
var firstIndex = data.indexOf(matchReg);
|
||||||
data = data.substring(firstIndex + matchReg.length, data.length)
|
data = data.substring(firstIndex + matchReg.length, data.length)
|
||||||
|
@ -69,7 +64,6 @@ struct BasicTestResourceManagerPage {
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
|
@ -97,7 +97,7 @@ struct CompressPage {
|
||||||
data.push($r('app.media.jpgSample'))
|
data.push($r('app.media.jpgSample'))
|
||||||
|
|
||||||
console.info("asasd start compress")
|
console.info("asasd start compress")
|
||||||
ImageKnife.with()
|
globalThis.ImageKnife
|
||||||
.compressBuilder()
|
.compressBuilder()
|
||||||
.load(data)
|
.load(data)
|
||||||
.ignoreBy(100)
|
.ignoreBy(100)
|
||||||
|
@ -137,7 +137,8 @@ struct CompressPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.info("asasd start compress")
|
console.info("asasd start compress")
|
||||||
ImageKnife.with()
|
|
||||||
|
globalThis.ImageKnife
|
||||||
.compressBuilder()
|
.compressBuilder()
|
||||||
.load(data)
|
.load(data)
|
||||||
.ignoreBy(100)
|
.ignoreBy(100)
|
|
@ -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%')
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,8 +22,6 @@ import {RoundedCornersTransformation} from '@ohos/imageknife'
|
||||||
struct FrescoImageTestCasePage {
|
struct FrescoImageTestCasePage {
|
||||||
|
|
||||||
@State progresshint:string = "输出加载百分比回调信息"
|
@State progresshint:string = "输出加载百分比回调信息"
|
||||||
|
|
||||||
|
|
||||||
@State imageKnifeOption1: ImageKnifeOption =
|
@State imageKnifeOption1: ImageKnifeOption =
|
||||||
{
|
{
|
||||||
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
loadSrc: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83ericA1Mv66TwicuYOtbDMBcUhv1aa9RJBeAn9uURfcZD0AUGrJebAn1g2AjN0vb2E1XTET7fTuLBNmA/132",
|
|
@ -13,13 +13,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import router from '@system.router';
|
import router from '@system.router';
|
||||||
import {Pngj} from '@ohos/imageknife'
|
|
||||||
|
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct Index {
|
struct IndexFunctionDemo {
|
||||||
@State hint1:string = '启用网络模拟加载替换网络加载'
|
@State hint1: string = '启用网络模拟加载替换网络加载'
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
Scroll() {
|
||||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
|
@ -148,12 +149,20 @@ struct Index {
|
||||||
console.log("pages/pngjTestCasePage 页面跳转")
|
console.log("pages/pngjTestCasePage 页面跳转")
|
||||||
router.push({ uri: "pages/pngjTestCasePage" });
|
router.push({ uri: "pages/pngjTestCasePage" });
|
||||||
}).margin({ top: 15 })
|
}).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%')
|
.width('100%')
|
||||||
|
@ -164,12 +173,6 @@ struct Index {
|
||||||
}
|
}
|
||||||
|
|
||||||
onBackPress() {
|
onBackPress() {
|
||||||
let cache = ImageKnife.getMemoryCache();
|
|
||||||
cache.print()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var ImageKnife;
|
|
||||||
var defaultTemp = globalThis.exports.default
|
|
||||||
if (defaultTemp != undefined) {
|
|
||||||
ImageKnife = defaultTemp.data.imageKnife;
|
|
||||||
}
|
|
|
@ -22,27 +22,19 @@ struct IndexFresco {
|
||||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
Button("测试控件隐藏与展示和动画")
|
Button("测试控件隐藏与展示和动画")
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
router.push({ uri: "pages/frescoLayerTestCasePage" });
|
router.push({ uri: "pages/frescoLayerTestCasePage" });
|
||||||
}).margin({ top: 15 })
|
}).margin({ top: 15 })
|
||||||
Button("测试自定义控件FrescoImage的加载百分比")
|
Button("测试自定义控件FrescoImage的加载百分比")
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
router.push({ uri: "pages/frescoImageTestCasePage" });
|
router.push({ uri: "pages/frescoImageTestCasePage" });
|
||||||
}).margin({ top: 15 })
|
}).margin({ top: 15 })
|
||||||
Button("测试自定义控件FrescoImage重试Retry")
|
Button("测试自定义控件FrescoImage重试Retry")
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
router.push({ uri: "pages/frescoRetryTestCasePage" });
|
router.push({ uri: "pages/frescoRetryTestCasePage" });
|
||||||
}).margin({ top: 15 })
|
}).margin({ top: 15 })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height('100%')
|
.height('100%')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,20 +13,33 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import router from '@system.router';
|
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 resourceManager from '@ohos.resourceManager';
|
||||||
import {FileUtils} from '@ohos/imageknife'
|
import { FileUtils } from '@ohos/imageknife'
|
||||||
import featureability from '@ohos.ability.featureAbility'
|
import featureability from '@ohos.ability.featureAbility'
|
||||||
import ArkWorker from '@ohos.worker'
|
import ArkWorker from '@ohos.worker'
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct PngjTestCasePage {
|
struct PngjTestCasePage {
|
||||||
pngSource: ArrayBuffer = new ArrayBuffer(0);
|
pngSource: ArrayBuffer = new ArrayBuffer(0);
|
||||||
rootFolder: string = '';
|
rootFolder: string = '';
|
||||||
@State hint1: string = 'readPngImageInfo内容展示'
|
@State hint1: string = 'readPngImageInfo内容展示'
|
||||||
@State hint2: string = 'readPngImage内容展示'
|
@State hint2: string = 'readPngImage内容展示'
|
||||||
@State hint3: string = 'writePngWithString内容展示'
|
@State hint3: string = 'writePngWithString内容展示'
|
||||||
@State hint4: string = 'writePngWithString内容展示'
|
@State hint4: string = 'writePngWithString内容展示'
|
||||||
|
@State hint5: string = '测试readMetadata'
|
||||||
|
@State hint6: string = '测试writeMetadata'
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
Scroll() {
|
||||||
|
@ -36,25 +49,15 @@ struct PngjTestCasePage {
|
||||||
Button('点击获取Png图片buffer').fontSize(20)
|
Button('点击获取Png图片buffer').fontSize(20)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
|
|
||||||
featureability.getContext()
|
this.rootFolder = globalThis.ImageKnife.getImageKnifeContext().filesDir;
|
||||||
.getFilesDir()
|
|
||||||
.then((data) => {
|
|
||||||
this.rootFolder = data;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('点击获取Png图片buffer 路径获取失败 err:' + err)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
resourceManager.getResourceManager()
|
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.Tomato').id)
|
||||||
.then(result => {
|
.then(data => {
|
||||||
result.getMedia($r('app.media.Tomato').id)
|
this.pngSource = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||||
.then(data => {
|
})
|
||||||
this.pngSource = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
.catch(err => {
|
||||||
})
|
console.log('点击获取Png图片buffer err=' + err)
|
||||||
.catch(err => {
|
|
||||||
console.log('点击获取Png图片buffer err=' + err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -103,6 +106,7 @@ struct PngjTestCasePage {
|
||||||
}).margin({ top: 5, left: 10 })
|
}).margin({ top: 5, left: 10 })
|
||||||
}.width('100%')
|
}.width('100%')
|
||||||
.height(60).backgroundColor(Color.Pink)
|
.height(60).backgroundColor(Color.Pink)
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
Button('测试readPngImageInfo')
|
Button('测试readPngImageInfo')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
|
@ -114,7 +118,10 @@ struct PngjTestCasePage {
|
||||||
Button('测试readPngImageAsync')
|
Button('测试readPngImageAsync')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let pngj = new Pngj();
|
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) => {
|
pngj.readPngImageAsync(worker, this.pngSource, (sender, value) => {
|
||||||
this.pngSource = sender
|
this.pngSource = sender
|
||||||
this.hint2 = 'img with=' + value.width + ' img height=' + value.height
|
this.hint2 = 'img with=' + value.width + ' img height=' + value.height
|
||||||
|
@ -124,7 +131,10 @@ struct PngjTestCasePage {
|
||||||
Button('测试writePngWithStringAsync')
|
Button('测试writePngWithStringAsync')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let pngj = new Pngj();
|
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) => {
|
pngj.writePngWithStringAsync(worker, 'hello world', this.pngSource, (sender, value) => {
|
||||||
this.pngSource = sender
|
this.pngSource = sender
|
||||||
FileUtils.getInstance().createFileProcess(
|
FileUtils.getInstance().createFileProcess(
|
||||||
|
@ -138,7 +148,10 @@ struct PngjTestCasePage {
|
||||||
Button('测试writePngAsync')
|
Button('测试writePngAsync')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let pngj = new Pngj();
|
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) => {
|
pngj.writePngAsync(worker, this.pngSource, (sender, value) => {
|
||||||
this.pngSource = sender
|
this.pngSource = sender
|
||||||
FileUtils.getInstance().createFileProcess(
|
FileUtils.getInstance().createFileProcess(
|
||||||
|
@ -152,6 +165,38 @@ struct PngjTestCasePage {
|
||||||
}.width('100%')
|
}.width('100%')
|
||||||
.height(60).backgroundColor(Color.Pink)
|
.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)
|
Text(this.hint1)
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height(120)
|
.height(120)
|
||||||
|
@ -165,9 +210,9 @@ struct PngjTestCasePage {
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height(120)
|
.height(120)
|
||||||
}
|
}
|
||||||
|
.width('100%')
|
||||||
|
.height('100%')
|
||||||
}
|
}
|
||||||
.width('100%')
|
|
||||||
.height('100%')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {
|
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {
|
|
@ -53,12 +53,12 @@ struct StorageTestDiskLruCache {
|
||||||
.backgroundColor(Color.Blue)
|
.backgroundColor(Color.Blue)
|
||||||
Button("替换ImageKnife默认DiskLruCache并设置大小1M")
|
Button("替换ImageKnife默认DiskLruCache并设置大小1M")
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
DiskImageKnife.replaceDiskLruCache(1 * 1024 * 1024)
|
globalThis.ImageKnife.replaceDiskLruCache(1 * 1024 * 1024)
|
||||||
}).margin({top:15, bottom:15})
|
}).margin({top:15, bottom:15})
|
||||||
|
|
||||||
Button("替换ImageKnife默认DiskLruCache并设置大小30M")
|
Button("替换ImageKnife默认DiskLruCache并设置大小30M")
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
DiskImageKnife.replaceDiskLruCache(30 * 1024 * 1024)
|
globalThis.ImageKnife.replaceDiskLruCache(30 * 1024 * 1024)
|
||||||
}).margin({top:15, bottom:15})
|
}).margin({top:15, bottom:15})
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
|
@ -170,19 +170,24 @@ struct StorageTestDiskLruCache {
|
||||||
request.addAllCacheInfoCallback(this.imageKnifeOption.allCacheInfoCallback)
|
request.addAllCacheInfoCallback(this.imageKnifeOption.allCacheInfoCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
DiskImageKnife.call(request);
|
globalThis.ImageKnife.call(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
imageKnifeChangeSource(data:ImageKnifeData) {
|
imageKnifeChangeSource(data:ImageKnifeData) {
|
||||||
this.imageKnifeSpecialFixed(data);
|
this.imageKnifeSpecialFixed(data);
|
||||||
|
|
||||||
//查看mImageKnife中的DiskLruCache
|
|
||||||
let disk = DiskImageKnife.getDiskMemoryCache();
|
// 由于异步写入,可能读取disklrucache的时候还没删成功,为了保证成功删除这里使用了延时
|
||||||
let showDisk = ''
|
setTimeout(() => {
|
||||||
disk.foreachDiskLruCache((value, key, map) => {
|
//查看mImageKnife中的DiskLruCache
|
||||||
showDisk += "key=" + key + "&value=" + value;
|
let disk = globalThis.ImageKnife.getDiskMemoryCache();
|
||||||
})
|
let showDisk = ''
|
||||||
this.logText = "日志结果:" + showDisk;
|
disk.foreachDiskLruCache((value, key, map) => {
|
||||||
|
showDisk += "key=" + key + "&value=" + value;
|
||||||
|
})
|
||||||
|
this.logText = "日志结果:" + showDisk;
|
||||||
|
}, 2000)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imageKnifeSpecialFixed(data:ImageKnifeData) {
|
imageKnifeSpecialFixed(data:ImageKnifeData) {
|
||||||
|
@ -226,7 +231,7 @@ struct StorageTestDiskLruCache {
|
||||||
console.log("ImageKnife占位图输出=String 拥有上一个图片类型 上一个是SVG")
|
console.log("ImageKnife占位图输出=String 拥有上一个图片类型 上一个是SVG")
|
||||||
this.normalPixelMap = false;
|
this.normalPixelMap = false;
|
||||||
this.normalResource = 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);
|
console.log("firstIndex=" + firstIndex);
|
||||||
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
||||||
console.log("suffix =" + suffix);
|
console.log("suffix =" + suffix);
|
||||||
|
@ -238,7 +243,7 @@ struct StorageTestDiskLruCache {
|
||||||
|
|
||||||
this.normalPixelMap = false;
|
this.normalPixelMap = false;
|
||||||
this.normalResource = 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);
|
console.log("firstIndex=" + firstIndex);
|
||||||
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
||||||
console.log("suffix =" + suffix);
|
console.log("suffix =" + suffix);
|
||||||
|
@ -280,7 +285,7 @@ struct StorageTestDiskLruCache {
|
||||||
console.log("ImageKnife占位图输出=String 没有上一个图片类型")
|
console.log("ImageKnife占位图输出=String 没有上一个图片类型")
|
||||||
this.normalPixelMap = false;
|
this.normalPixelMap = false;
|
||||||
this.normalResource = 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);
|
console.log("firstIndex=" + firstIndex);
|
||||||
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
let suffix = (data.imageKnifeValue as string).substring(firstIndex, (data.imageKnifeValue as string).length)
|
||||||
console.log("suffix =" + suffix);
|
console.log("suffix =" + suffix);
|
||||||
|
@ -318,4 +323,3 @@ struct StorageTestDiskLruCache {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var DiskImageKnife = globalThis.exports.default.data.imageKnife
|
|
|
@ -12,7 +12,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import featureAbility from '@ohos.ability.featureAbility';
|
|
||||||
import {LruCache} from '@ohos/imageknife'
|
import {LruCache} from '@ohos/imageknife'
|
||||||
|
|
||||||
function getRandomInt(min, max) {
|
function getRandomInt(min, max) {
|
|
@ -207,4 +207,4 @@ struct TestAllCacheInfoPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
var ImageKnife = globalThis.ImageKnife
|
|
@ -31,17 +31,17 @@ struct TestGifDontAnimatePage {
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
Scroll() {
|
||||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Column() {
|
||||||
Flex({direction:FlexDirection.Row}){
|
Flex({ direction: FlexDirection.Row }) {
|
||||||
Button('本地资源gif')
|
Button('本地资源gif')
|
||||||
.onClick(()=>{
|
.onClick(() => {
|
||||||
this.imageKnifeOption1 = {
|
this.imageKnifeOption1 = {
|
||||||
loadSrc: $r('app.media.gifSample'),
|
loadSrc: $r('app.media.gifSample'),
|
||||||
size: { width: 300, height: 300 },
|
size: { width: 300, height: 300 },
|
||||||
placeholderSrc: $r('app.media.icon_loading'),
|
placeholderSrc: $r('app.media.icon_loading'),
|
||||||
errorholderSrc: $r('app.media.icon_failed'),
|
errorholderSrc: $r('app.media.icon_failed'),
|
||||||
margin:{left:15,top:15,right:15,bottom:15}
|
margin: { left: 15, top: 15, right: 15, bottom: 15 }
|
||||||
}
|
}
|
||||||
|
|
||||||
}).margin({left:15}).backgroundColor(Color.Grey)
|
}).margin({left:15}).backgroundColor(Color.Grey)
|
||||||
Button('本地资源gif静态')
|
Button('本地资源gif静态')
|
||||||
|
@ -95,5 +95,4 @@ struct TestGifDontAnimatePage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ImageKnife = globalThis.ImageKnife
|
||||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
|
@ -105,4 +105,3 @@ struct TestImageKnifeOptionChangedPage2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
|
|
@ -23,7 +23,10 @@ struct TestMultiThreadWorkerPage2 {
|
||||||
Button("创建Worker向子线程发送携带Arraybuffer数据")
|
Button("创建Worker向子线程发送携带Arraybuffer数据")
|
||||||
.margin({ top: 20 })
|
.margin({ top: 20 })
|
||||||
.onClick(() => {
|
.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) {
|
worker.onerror = function (data) {
|
||||||
console.info("worker:: receive onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno);
|
console.info("worker:: receive onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno);
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@
|
||||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||||
import {RequestOption} from '@ohos/imageknife'
|
import {RequestOption} from '@ohos/imageknife'
|
||||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
|
@ -72,18 +72,18 @@ struct TestPreloadPage {
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Scroll() {
|
Scroll() {
|
||||||
Flex({ direction: FlexDirection.Column }) {
|
Column() {
|
||||||
Flex({ direction: FlexDirection.Column }) {
|
Column() {
|
||||||
Flex({ direction: FlexDirection.Row }) {
|
Flex({ direction: FlexDirection.Row }) {
|
||||||
Button('预加载本地资源gif')
|
Button('预加载本地资源gif')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let request = new RequestOption();
|
let request = new RequestOption();
|
||||||
request.load($r('app.media.gifSample'))
|
request.load($r('app.media.gifSample'))
|
||||||
.setImageViewSize({ width: 300, height: 300 })
|
.setImageViewSize({ width: 300, height: 300 })
|
||||||
.addListener((err, data) => {
|
.addListener((err, data) => {
|
||||||
if (err && err.length > 0) {
|
if (err && err.length > 0) {
|
||||||
console.log('预加载本地资源gif 出现错误! err=' + err)
|
console.log('预加载本地资源gif 出现错误! err=' + err)
|
||||||
} else {
|
} else {
|
||||||
console.log('预加载本地资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
console.log('预加载本地资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -216,17 +216,17 @@ struct TestPreloadPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Column }) {
|
Column() {
|
||||||
Flex({ direction: FlexDirection.Row }) {
|
Flex({ direction: FlexDirection.Row }) {
|
||||||
Button('预加载本地资源svg')
|
Button('预加载本地资源svg')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let request = new RequestOption();
|
let request = new RequestOption();
|
||||||
request.load($r('app.media.svgSample'))
|
request.load($r('app.media.svgSample'))
|
||||||
.setImageViewSize({ width: 300, height: 300 })
|
.setImageViewSize({ width: 300, height: 300 })
|
||||||
.addListener((err, data) => {
|
.addListener((err, data) => {
|
||||||
if (err && err.length > 0) {
|
if (err && err.length > 0) {
|
||||||
console.log('预加载本地资源svg 出现错误! err=' + err)
|
console.log('预加载本地资源svg 出现错误! err=' + err)
|
||||||
} else {
|
} else {
|
||||||
console.log('预加载本地资源svg成功! imageKnifedata=' + JSON.stringify(data))
|
console.log('预加载本地资源svg成功! imageKnifedata=' + JSON.stringify(data))
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -296,17 +296,17 @@ struct TestPreloadPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Column }) {
|
Column() {
|
||||||
Flex({ direction: FlexDirection.Row }) {
|
Flex({ direction: FlexDirection.Row }) {
|
||||||
Button('预加载本地资源webp')
|
Button('预加载本地资源webp')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let request = new RequestOption();
|
let request = new RequestOption();
|
||||||
request.load($r('app.media.jpgSample'))
|
request.load($r('app.media.jpgSample'))
|
||||||
.setImageViewSize({ width: 300, height: 300 })
|
.setImageViewSize({ width: 300, height: 300 })
|
||||||
.addListener((err, data) => {
|
.addListener((err, data) => {
|
||||||
if (err && err.length > 0) {
|
if (err && err.length > 0) {
|
||||||
console.log('预加载本地资源webp 出现错误! err=' + err)
|
console.log('预加载本地资源webp 出现错误! err=' + err)
|
||||||
} else {
|
} else {
|
||||||
console.log('预加载本地资源webp成功! imageKnifedata=' + JSON.stringify(data))
|
console.log('预加载本地资源webp成功! imageKnifedata=' + JSON.stringify(data))
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -374,17 +374,17 @@ struct TestPreloadPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Column }) {
|
Column() {
|
||||||
Flex({ direction: FlexDirection.Row }) {
|
Flex({ direction: FlexDirection.Row }) {
|
||||||
Button('预加载本地资源bmp')
|
Button('预加载本地资源bmp')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let request = new RequestOption();
|
let request = new RequestOption();
|
||||||
request.load($r('app.media.bmpSample'))
|
request.load($r('app.media.bmpSample'))
|
||||||
.setImageViewSize({ width: 300, height: 300 })
|
.setImageViewSize({ width: 300, height: 300 })
|
||||||
.addListener((err, data) => {
|
.addListener((err, data) => {
|
||||||
if (err && err.length > 0) {
|
if (err && err.length > 0) {
|
||||||
console.log('预加载本地资源bmp 出现错误! err=' + err)
|
console.log('预加载本地资源bmp 出现错误! err=' + err)
|
||||||
} else {
|
} else {
|
||||||
console.log('预加载本地资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
console.log('预加载本地资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -452,17 +452,17 @@ struct TestPreloadPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Column }) {
|
Column() {
|
||||||
Flex({ direction: FlexDirection.Row }) {
|
Flex({ direction: FlexDirection.Row }) {
|
||||||
Button('预加载本地资源png')
|
Button('预加载本地资源png')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let request = new RequestOption();
|
let request = new RequestOption();
|
||||||
request.load($r('app.media.pngSample'))
|
request.load($r('app.media.pngSample'))
|
||||||
.setImageViewSize({ width: 300, height: 300 })
|
.setImageViewSize({ width: 300, height: 300 })
|
||||||
.addListener((err, data) => {
|
.addListener((err, data) => {
|
||||||
if (err && err.length > 0) {
|
if (err && err.length > 0) {
|
||||||
console.log('预加载本地资源png 出现错误! err=' + err)
|
console.log('预加载本地资源png 出现错误! err=' + err)
|
||||||
} else {
|
} else {
|
||||||
console.log('预加载本地资源png成功! imageKnifedata=' + JSON.stringify(data))
|
console.log('预加载本地资源png成功! imageKnifedata=' + JSON.stringify(data))
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -530,17 +530,17 @@ struct TestPreloadPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Flex({ direction: FlexDirection.Column }) {
|
Column() {
|
||||||
Flex({ direction: FlexDirection.Row }) {
|
Flex({ direction: FlexDirection.Row }) {
|
||||||
Button('预加载本地资源jpg')
|
Button('预加载本地资源jpg')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
let request = new RequestOption();
|
let request = new RequestOption();
|
||||||
request.load($r('app.media.jpgSample'))
|
request.load($r('app.media.jpgSample'))
|
||||||
.setImageViewSize({ width: 300, height: 300 })
|
.setImageViewSize({ width: 300, height: 300 })
|
||||||
.addListener((err, data) => {
|
.addListener((err, data) => {
|
||||||
if (err && err.length > 0) {
|
if (err && err.length > 0) {
|
||||||
console.log('预加载本地资源jpg 出现错误! err=' + err)
|
console.log('预加载本地资源jpg 出现错误! err=' + err)
|
||||||
} else {
|
} else {
|
||||||
console.log('预加载本地资源jpg成功! imageKnifedata=' + JSON.stringify(data))
|
console.log('预加载本地资源jpg成功! imageKnifedata=' + JSON.stringify(data))
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -608,9 +608,11 @@ struct TestPreloadPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height('100%')
|
.height('100%')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aboutToAppear() {
|
aboutToAppear() {
|
||||||
|
@ -619,4 +621,4 @@ struct TestPreloadPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var ImageKnife = globalThis.exports.default.data.imageKnife
|
var ImageKnife = globalThis.ImageKnife
|
|
@ -36,9 +36,7 @@ struct TestResourceManagerPage {
|
||||||
.height(300)
|
.height(300)
|
||||||
Button("点击执行ResourceManager的Base64")
|
Button("点击执行ResourceManager的Base64")
|
||||||
.onClick(()=>{
|
.onClick(()=>{
|
||||||
resourceManager.getResourceManager()
|
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMediaBase64($r('app.media.jpgSample').id)
|
||||||
.then(result => {
|
|
||||||
result.getMediaBase64($r('app.media.jpgSample').id)
|
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log("jpgSample data=" + data)
|
console.log("jpgSample data=" + data)
|
||||||
let matchUseLess = ";base64,";
|
let matchUseLess = ";base64,";
|
||||||
|
@ -55,15 +53,11 @@ struct TestResourceManagerPage {
|
||||||
|
|
||||||
this.imageKnifeData = newImageKnifeData;
|
this.imageKnifeData = newImageKnifeData;
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
Button("点击执行ResourceManager的非Base64")
|
Button("点击执行ResourceManager的非Base64")
|
||||||
.margin({top:25})
|
.margin({top:25})
|
||||||
.onClick(()=>{
|
.onClick(()=>{
|
||||||
resourceManager.getResourceManager()
|
globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.pngSample').id)
|
||||||
.then(result => {
|
|
||||||
result.getMedia($r('app.media.pngSample').id)
|
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log("arrayBuffer data=" + data)
|
console.log("arrayBuffer data=" + data)
|
||||||
let fileTypeUtil = new FileTypeUtil();
|
let fileTypeUtil = new FileTypeUtil();
|
||||||
|
@ -73,8 +67,6 @@ struct TestResourceManagerPage {
|
||||||
newImageKnifeData.imageKnifeType = typeValue
|
newImageKnifeData.imageKnifeType = typeValue
|
||||||
this.imageKnifeData = newImageKnifeData;
|
this.imageKnifeData = newImageKnifeData;
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,17 +12,21 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {RequestOption} from '@ohos/imageknife'
|
import { RequestOption } from '@ohos/imageknife'
|
||||||
import {CropCircleWithBorderTransformation} from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation'
|
import { CropCircleTransformation } from '@ohos/imageknife'
|
||||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
import { RoundedCornersTransformation } from '@ohos/imageknife'
|
||||||
import {CropSquareTransformation} from '@ohos/imageknife'
|
import {
|
||||||
import {CropTransformation} from '@ohos/imageknife'
|
CropCircleWithBorderTransformation
|
||||||
import {CropType} from '@ohos/imageknife'
|
} from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation'
|
||||||
import {GrayscaleTransformation} from '@ohos/imageknife'
|
import { RotateImageTransformation } from '@ohos/imageknife'
|
||||||
import {BrightnessFilterTransformation} from '@ohos/imageknife'
|
import { CropSquareTransformation } from '@ohos/imageknife'
|
||||||
import {ContrastFilterTransformation} from '@ohos/imageknife'
|
import { CropTransformation } from '@ohos/imageknife'
|
||||||
import {InvertFilterTransformation} from '@ohos/imageknife'
|
import { CropType } from '@ohos/imageknife'
|
||||||
import {SepiaFilterTransformation} 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 {SketchFilterTransformation} from '@ohos/imageknife'
|
||||||
import {BlurTransformation} from '@ohos/imageknife'
|
import {BlurTransformation} from '@ohos/imageknife'
|
||||||
import {PixelationFilterTransformation} 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
|
|
@ -13,9 +13,16 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import arkWorker from '@ohos.worker';
|
import arkWorker from '@ohos.worker';
|
||||||
|
|
||||||
import {handler} from '@ohos/imageknife/src/main/ets/components/imageknife/pngj/PngWork'
|
import {handler} from '@ohos/imageknife/src/main/ets/components/imageknife/pngj/PngWork'
|
||||||
|
|
||||||
arkWorker.parentPort.onmessage = handler
|
arkWorker.parentPort.onmessage = handler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,18 @@
|
||||||
{
|
{
|
||||||
"string": [
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "entry_desc",
|
||||||
|
"value": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MainAbility_desc",
|
||||||
|
"value": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MainAbility_label",
|
||||||
|
"value": "label"
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "ImageKnife_OHOS",
|
"name": "ImageKnife_OHOS",
|
||||||
"value": "ImageKnife_OHOS"
|
"value": "ImageKnife_OHOS"
|
||||||
|
|
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import AbilityStage from "@ohos.application.AbilityStage"
|
||||||
|
|
||||||
|
export default class TestAbilityStage extends AbilityStage {
|
||||||
|
onCreate() {
|
||||||
|
console.log("[Demo] TestAbilityStage onCreate")
|
||||||
|
}
|
||||||
|
}
|
|
@ -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')
|
||||||
|
}
|
||||||
|
};
|
|
@ -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')
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,18 +1,4 @@
|
||||||
/*
|
import router from '@ohos.router';
|
||||||
* 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';
|
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
|
@ -20,7 +6,6 @@ struct Index {
|
||||||
aboutToAppear() {
|
aboutToAppear() {
|
||||||
console.info('TestAbility index aboutToAppear')
|
console.info('TestAbility index aboutToAppear')
|
||||||
}
|
}
|
||||||
|
|
||||||
@State message: string = 'Hello World'
|
@State message: string = 'Hello World'
|
||||||
build() {
|
build() {
|
||||||
Row() {
|
Row() {
|
||||||
|
|
|
@ -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 TestRunner from '@ohos.application.testRunner'
|
||||||
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
|
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
|
||||||
|
|
||||||
|
@ -20,25 +6,24 @@ var abilityDelegatorArguments = undefined
|
||||||
|
|
||||||
function translateParamsToString(parameters) {
|
function translateParamsToString(parameters) {
|
||||||
const keySet = new Set([
|
const keySet = new Set([
|
||||||
'-s class', '-s notClass', '-s suite', '-s itName',
|
'-s class', '-s notClass', '-s suite', '-s it',
|
||||||
'-s level', '-s testType', '-s size', '-s timeout',
|
'-s level', '-s testType', '-s size', '-s timeout'
|
||||||
'-s package'
|
|
||||||
])
|
])
|
||||||
let targetParams = '';
|
let targetParams = '';
|
||||||
for (const key in parameters) {
|
for (const key in parameters) {
|
||||||
if (keySet.has(key)) {
|
if (keySet.has(key)) {
|
||||||
targetParams += ' ' + key + ' ' + parameters[key]
|
targetParams = `${targetParams} ${key} ${parameters[key]}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return targetParams.trim()
|
return targetParams.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onAbilityCreateCallback() {
|
async function onAbilityCreateCallback() {
|
||||||
console.log('onAbilityCreateCallback');
|
console.log("onAbilityCreateCallback");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addAbilityMonitorCallback(err: any) {
|
async function addAbilityMonitorCallback(err: any) {
|
||||||
console.info('addAbilityMonitorCallback : ' + JSON.stringify(err))
|
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class OpenHarmonyTestRunner implements TestRunner {
|
export default class OpenHarmonyTestRunner implements TestRunner {
|
||||||
|
@ -46,21 +31,20 @@ export default class OpenHarmonyTestRunner implements TestRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
onPrepare() {
|
onPrepare() {
|
||||||
console.info('OpenHarmonyTestRunner OnPrepare')
|
console.info("OpenHarmonyTestRunner OnPrepare ")
|
||||||
}
|
}
|
||||||
|
|
||||||
onRun() {
|
async onRun() {
|
||||||
console.log('OpenHarmonyTestRunner onRun run')
|
console.log('OpenHarmonyTestRunner onRun run')
|
||||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
||||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
||||||
|
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
|
||||||
let lMonitor = {
|
let lMonitor = {
|
||||||
abilityName: testAbilityName,
|
abilityName: testAbilityName,
|
||||||
onAbilityCreate: onAbilityCreateCallback,
|
onAbilityCreate: onAbilityCreateCallback,
|
||||||
};
|
};
|
||||||
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
|
|
||||||
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
|
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)
|
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
|
||||||
console.info('cmd : '+cmd)
|
console.info('cmd : '+cmd)
|
||||||
abilityDelegator.executeShellCommand(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.stdResult);
|
||||||
console.info('executeShellCommand : data : ' + d.exitCode);
|
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')
|
console.info('OpenHarmonyTestRunner onRun end')
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -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'
|
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index'
|
||||||
|
|
||||||
export default function abilityTest() {
|
export default function abilityTest() {
|
||||||
|
|
|
@ -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'
|
import abilityTest from './Ability.test'
|
||||||
|
|
||||||
export default function testsuite() {
|
export default function testsuite() {
|
||||||
|
|
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "white",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,12 +1,16 @@
|
||||||
{
|
{
|
||||||
"string": [
|
"string": [
|
||||||
{
|
{
|
||||||
"name": "description_TestAbility",
|
"name": "entry_test_desc",
|
||||||
"value": "eTS_Empty Ability"
|
"value": "i am an entry for tv"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "entry_TestAbility",
|
"name": "TestAbility_desc",
|
||||||
"value": "entry_TestAbility"
|
"value": "the tv entry test ability"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "TestAbility_label",
|
||||||
|
"value": "tvBase"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"src": [
|
||||||
|
"TestAbility/pages/index"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue