diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index 77024bd..78fb9bc 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -286,6 +286,13 @@ struct IndexFunctionDemo { router.pushUrl({ url: "pages/testManyGifLoadWithPage" }); }).margin({ top: 5, left: 3 }) }.width('100%').height(60).backgroundColor(Color.Pink) + Text("测试图片抗锯齿").fontSize(15) + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Button("测试图片抗锯齿") + .onClick(() => { + router.pushUrl({ url: "pages/testImageAntiAliasingWithPage" }); + }).margin({ top: 5, left: 3 }) + }.width('100%').height(60).backgroundColor(Color.Pink) } } .width('100%') diff --git a/entry/src/main/ets/pages/testImageAntiAliasingWithPage.ets b/entry/src/main/ets/pages/testImageAntiAliasingWithPage.ets new file mode 100644 index 0000000..bc9713a --- /dev/null +++ b/entry/src/main/ets/pages/testImageAntiAliasingWithPage.ets @@ -0,0 +1,65 @@ +/* + * 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 {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {RoundedCornersTransformation} from '@ohos/libraryimageknife' + +@Entry +@Component +struct TestImageAntiAliasingWithPage { + @State imageKnifeOption1: ImageKnifeOption = + { + loadSrc: "https://thirdwx.qlogo.cn/mmopen/xxxxx", + + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed'), + }; + @State imageKnifeOption: ImageKnifeOption = + { + loadSrc: "https://hbimg.huabanimg.com/xxxxx", + + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed'), + }; + @State imageKnifeOption3: ImageKnifeOption = + { + loadSrc: "https://hbimg.huabanimg.com/xxxxx", + + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed'), + }; + @State imageKnifeOption4: ImageKnifeOption = + { + loadSrc: "https://hbimg.huabanimg.com/xxxxx", + + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed'), + }; + + build() { + Scroll() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(600).height(600) + Image($r('app.media.icon_failed')) + .width(600).height(600).margin(15) + .overlay('png', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + .interpolation(ImageInterpolation.High) + } + } + .width('100%') + .height('100%') + } +} diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index be0efeb..82b2574 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -33,6 +33,7 @@ "pages/SignatureTestPage", "pages/hspCacheTestPage", "pages/testManyNetImageLoadWithPage", - "pages/testManyGifLoadWithPage" + "pages/testManyGifLoadWithPage", + "pages/testImageAntiAliasingWithPage" ] } \ No newline at end of file diff --git a/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets index 5a55812..0ac6b28 100644 --- a/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -115,6 +115,10 @@ export struct ImageKnifeComponent { } }) .onReady(() => { + let ctx = this.context + ctx.imageSmoothingEnabled = true + ctx.imageSmoothingQuality = 'high' + this.canvasHasReady = true; if (this.onReadyNext) { LogUtil.log('ImageKnifeComponent onReadyNext is running!')