From 6730ef9583354b44143fbbde35b24688ca35bc07 Mon Sep 17 00:00:00 2001
From: liuhaikang <893370936@qq.com>
Date: Thu, 7 Sep 2023 10:45:16 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9Esvg=E5=9B=BE=E7=89=87demo?=
=?UTF-8?q?=E7=A4=BA=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: liuhaikang <893370936@qq.com>
---
entry/src/main/ets/pages/svgTestCasePage.ets | 36 +++++++++++++++++--
.../src/main/resources/base/media/iconsvg.svg | 18 ++++++++++
2 files changed, 51 insertions(+), 3 deletions(-)
create mode 100644 entry/src/main/resources/base/media/iconsvg.svg
diff --git a/entry/src/main/ets/pages/svgTestCasePage.ets b/entry/src/main/ets/pages/svgTestCasePage.ets
index 025bc3b..4c3516c 100644
--- a/entry/src/main/ets/pages/svgTestCasePage.ets
+++ b/entry/src/main/ets/pages/svgTestCasePage.ets
@@ -18,7 +18,8 @@ import {SVGParseImpl} from '@ohos/imageknife'
@Component
struct svgTestCasePage {
- @State pixels:PixelMap = undefined
+ @State svgSamplePixelMap:PixelMap = undefined
+ @State svgIconPixelMap:PixelMap = undefined
build() {
Scroll() {
@@ -32,7 +33,7 @@ struct svgTestCasePage {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
let svgImpl = new SVGParseImpl();
svgImpl.parseSvg(data.buffer).then((pixelmap)=>{
- this.pixels = pixelmap;
+ this.svgSamplePixelMap = pixelmap;
})
})
.catch(err => {
@@ -46,7 +47,36 @@ struct svgTestCasePage {
Text("下面为展示图片区域").margin({top:5})
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
- Image(this.pixels)
+ Image(this.svgSamplePixelMap)
+ .width(400)
+ .height(400)
+ .backgroundColor(Color.Pink)
+ }.width(400).height(400).margin({top:10}).backgroundColor(Color.Pink)
+
+ Flex({direction:FlexDirection.Row}){
+ Button("加载SVG图片")
+ .onClick(()=>{
+
+ globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.iconsvg').id)
+ .then(data => {
+ console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
+ let svgImpl = new SVGParseImpl();
+ svgImpl.parseSvg(data.buffer).then((pixelmap)=>{
+ this.svgIconPixelMap = pixelmap;
+ })
+ })
+ .catch(err => {
+ console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
+ })
+
+ }).margin({left:5}).backgroundColor(Color.Blue)
+
+ }
+ .margin({top:15})
+
+ Text("下面为展示图片区域").margin({top:5})
+ Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
+ Image(this.svgIconPixelMap)
.width(400)
.height(400)
.backgroundColor(Color.Pink)
diff --git a/entry/src/main/resources/base/media/iconsvg.svg b/entry/src/main/resources/base/media/iconsvg.svg
new file mode 100644
index 0000000..0cdac6c
--- /dev/null
+++ b/entry/src/main/resources/base/media/iconsvg.svg
@@ -0,0 +1,18 @@
+
+
\ No newline at end of file
From 8fa84463ee91bbfca4b7a820efb5b23a84876bd4 Mon Sep 17 00:00:00 2001
From: liuhaikang <893370936@qq.com>
Date: Thu, 7 Sep 2023 11:40:36 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=BF=E6=8D=A2svg=E5=9B=BE=E7=89=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: liuhaikang <893370936@qq.com>
---
entry/src/main/ets/pages/svgTestCasePage.ets | 2 +-
.../src/main/resources/base/media/iconsvg.svg | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
create mode 100644 entry/src/main/resources/base/media/iconsvg.svg
diff --git a/entry/src/main/ets/pages/svgTestCasePage.ets b/entry/src/main/ets/pages/svgTestCasePage.ets
index 025bc3b..84e6671 100644
--- a/entry/src/main/ets/pages/svgTestCasePage.ets
+++ b/entry/src/main/ets/pages/svgTestCasePage.ets
@@ -27,7 +27,7 @@ struct svgTestCasePage {
Button("加载SVG图片")
.onClick(()=>{
- globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.svgSample').id)
+ globalThis.ImageKnife.getImageKnifeContext().resourceManager.getMedia($r('app.media.iconsvg').id)
.then(data => {
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
let svgImpl = new SVGParseImpl();
diff --git a/entry/src/main/resources/base/media/iconsvg.svg b/entry/src/main/resources/base/media/iconsvg.svg
new file mode 100644
index 0000000..f2fb75b
--- /dev/null
+++ b/entry/src/main/resources/base/media/iconsvg.svg
@@ -0,0 +1,18 @@
+
+
\ No newline at end of file