ImageKnife/entry/src/main/ets/pages/svgTestCasePage.ets

82 lines
2.8 KiB
Plaintext

/*
* Copyright (C) 2022 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 {SVGParseImpl} from '@ohos/libraryimageknife'
import { ImageKnifeComponent } from '@ohos/libraryimageknife'
import resourceManager from '@ohos.resourceManager';
import {BusinessError} from '@ohos.base'
import common from '@ohos.app.ability.common';
@Entry
@Component
struct svgTestCasePage {
@State svgSamplePixelMap?: Resource = undefined
@State svgIconPixelMap?: Resource = undefined
build() {
Scroll() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Flex({direction:FlexDirection.Row}){
Button("加载SVG图片")
.onClick(()=>{
this.svgSamplePixelMap = $r('app.media.svgSample')
}).margin({left:5}).backgroundColor(Color.Blue)
}
.margin({top:15})
Text("下面为展示图片区域").margin({top:5})
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
ImageKnifeComponent({imageKnifeOption:{
loadSrc:this.svgSamplePixelMap as Resource
}})
.width(400)
.height(400)
.backgroundColor(Color.Pink)
}.width(400).height(400).margin({top:10}).backgroundColor(Color.Pink)
Flex({direction:FlexDirection.Row}){
Button("加载SVG图片")
.onClick(()=>{
this.svgIconPixelMap = $r('app.media.iconsvg')
}).margin({left:5}).backgroundColor(Color.Blue)
}
.margin({top:15})
Text("下面为展示图片区域").margin({top:5})
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
ImageKnifeComponent({imageKnifeOption:{
loadSrc:this.svgIconPixelMap as Resource
}})
.width(400)
.height(400)
.backgroundColor(Color.Pink)
}.width(400).height(400).margin({top:10}).backgroundColor(Color.Pink)
}
}
.width('100%')
.height('100%')
}
aboutToAppear() {
console.log("aboutToAppear()")
}
typedArrayToBuffer(array: Uint8Array): ArrayBuffer {
return array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset)
}
}