canvas增加图片抗锯齿-代码格式修改

Signed-off-by: zourenjie <zourenjie1@h-partners.com>
This commit is contained in:
zourenjie 2023-12-26 17:32:14 +08:00
parent 08ae90f7e4
commit 607156887a
3 changed files with 13 additions and 16 deletions

View File

@ -286,11 +286,11 @@ struct IndexFunctionDemo {
router.pushUrl({ url: "pages/testManyGifLoadWithPage" });
}).margin({ top: 5, left: 3 })
}.width('100%').height(60).backgroundColor(Color.Pink)
Text("测试图片抗锯齿").fontSize(15)
Text('测试图片抗锯齿').fontSize(15)
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button("测试图片抗锯齿")
Button('测试图片抗锯齿')
.onClick(() => {
router.pushUrl({ url: "pages/testImageAntiAliasingWithPage" });
router.pushUrl({ url: 'pages/testImageAntiAliasingWithPage' });
}).margin({ top: 5, left: 3 })
}.width('100%').height(60).backgroundColor(Color.Pink)
}

View File

@ -12,10 +12,10 @@
* 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'
import { ImageKnifeComponent } from '@ohos/libraryimageknife'
import { ImageKnifeOption } from '@ohos/libraryimageknife'
import { RotateImageTransformation } from '@ohos/libraryimageknife'
import { RoundedCornersTransformation } from '@ohos/libraryimageknife'
@Entry
@Component
@ -23,28 +23,24 @@ 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'),
};
@ -54,7 +50,9 @@ struct TestImageAntiAliasingWithPage {
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)
.width(600)
.height(600)
.margin(15)
.overlay('png', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
.interpolation(ImageInterpolation.High)
}

View File

@ -115,10 +115,9 @@ export struct ImageKnifeComponent {
}
})
.onReady(() => {
let ctx = this.context
ctx.imageSmoothingEnabled = true
ctx.imageSmoothingQuality = 'high'
let ctx = this.context;
ctx.imageSmoothingEnabled = true;
ctx.imageSmoothingQuality = 'high';
this.canvasHasReady = true;
if (this.onReadyNext) {
LogUtil.log('ImageKnifeComponent onReadyNext is running!')