diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 6cbb7a6..aa6c080 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -164,6 +164,12 @@ struct Index { uri: 'pages/TestCacheDataPage', }); }) + Button("测试颜色变换").margin({top:10}).onClick(()=>{ + router.push({ + uri: 'pages/TestChangeColorPage', + }); + }) + } } .width('100%') .height('100%') diff --git a/entry/src/main/ets/pages/TestChangeColorPage.ets b/entry/src/main/ets/pages/TestChangeColorPage.ets new file mode 100644 index 0000000..87349bb --- /dev/null +++ b/entry/src/main/ets/pages/TestChangeColorPage.ets @@ -0,0 +1,97 @@ +import { drawing, common2D } from '@kit.ArkGraphics2D'; +import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'; + +@Entry +@Component +struct TestChangeColorPage { + private imageOne: Resource = $r('app.media.test'); + private imageTwo: Resource = $r('app.media.test'); + @State src: Resource = this.imageOne + @State src2: Resource = this.imageTwo + @State color: common2D.Color = { + alpha: 255, + red: 255, + green: 1, + blue: 1 + }; + @State DrawingColorFilterFirst: ColorFilter | undefined = undefined + + build() { + Column() { + Text("点击选择要更改的颜色").margin({ top: 20 }) + Row() { + Button("红色").backgroundColor(Color.Red).margin(5).onClick(() => { + this.color = { + alpha: 255, + red: 255, + green: 1, + blue: 1 + }; + }) + Button("黄色").backgroundColor(Color.Yellow).margin(5).onClick(() => { + this.color = { + alpha: 255, + red: 255, + green: 255, + blue: 1 + }; + }) + Button("绿色").backgroundColor(Color.Green).margin(5).onClick(() => { + this.color = { + alpha: 255, + red: 1, + green: 255, + blue: 1 + }; + }) + Button("蓝色").backgroundColor(Color.Blue).margin(5).onClick(() => { + this.color = { + alpha: 255, + red: 1, + green: 1, + blue: 255 + }; + }) + } + .width('100%') + .height(50) + .justifyContent(FlexAlign.Center) + + Text("原图:").margin({ top: 20 }) + ImageKnifeComponent({ + imageKnifeOption: new ImageKnifeOption({ + loadSrc: this.src + }) + }).width(110).height(110) + + Text("点击图片更改图片颜色:").margin({ top: 30 }) + ImageKnifeComponent({ + imageKnifeOption: new ImageKnifeOption({ + loadSrc: this.src, + drawingColorFilter: this.DrawingColorFilterFirst + }) + }) + .onClick(() => { + this.DrawingColorFilterFirst = + drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN); + }).width(110).height(110) + + Text("测试非svg图片变色").margin({ top: 30 }) + ImageKnifeComponent({ + imageKnifeOption: new ImageKnifeOption({ + loadSrc: $r('app.media.test'), + drawingColorFilter: drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN) + }) + }).width(110).height(110) + + Text("测试svg图片变色").margin({ top: 30 }) + ImageKnifeComponent({ + imageKnifeOption: new ImageKnifeOption({ + loadSrc: $r("app.media.test_svg"), + drawingColorFilter: drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN) + }) + }).width(110).height(110) + + }.width('100%').height('100%') + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/test.png b/entry/src/main/resources/base/media/test.png new file mode 100644 index 0000000..b0d65d0 Binary files /dev/null and b/entry/src/main/resources/base/media/test.png differ diff --git a/entry/src/main/resources/base/media/test_svg.svg b/entry/src/main/resources/base/media/test_svg.svg new file mode 100644 index 0000000..9910b1d --- /dev/null +++ b/entry/src/main/resources/base/media/test_svg.svg @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 7b16f4e..e553510 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -23,6 +23,7 @@ "pages/TestSetCustomImagePage", "pages/TestErrorHolderPage", "pages/TestTaskResourcePage", - "pages/TestCacheDataPage" + "pages/TestCacheDataPage", + "pages/TestChangeColorPage" ] } \ No newline at end of file