From aa3e362ec71278bf24e17a21f4f6b0cca3e9e8e7 Mon Sep 17 00:00:00 2001 From: LiAn <lian15@huawei.com> Date: Fri, 21 Jul 2023 12:19:02 +0000 Subject: [PATCH] update zh-cn/application-dev/ui/arkts-graphics-display.md. Signed-off-by: LiAn <lian15@huawei.com> --- .../ui/arkts-graphics-display.md | 209 +++++++++++++++++- 1 file changed, 208 insertions(+), 1 deletion(-) diff --git a/zh-cn/application-dev/ui/arkts-graphics-display.md b/zh-cn/application-dev/ui/arkts-graphics-display.md index 50c436787e..af984afc9b 100644 --- a/zh-cn/application-dev/ui/arkts-graphics-display.md +++ b/zh-cn/application-dev/ui/arkts-graphics-display.md @@ -268,7 +268,214 @@ struct MyComponent { } ``` - + + + +### 图片æ’值 + +当原图分辨率较低并且放大显示时,图片会模糊出现锯齿。这时å¯ä»¥ä½¿ç”¨interpolation属性对图片进行æ’值,使图片显示得更清晰。 + + +```ts +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + Image($r('app.media.grass')) + .width('40%') + .interpolation(ImageInterpolation.None) + .borderWidth(1) + .overlay("Interpolation.None", { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + .margin(10) + Image($r('app.media.grass')) + .width('40%') + .interpolation(ImageInterpolation.Low) + .borderWidth(1) + .overlay("Interpolation.Low", { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + .margin(10) + }.width('100%') + .justifyContent(FlexAlign.Center) + + Row() { + Image($r('app.media.grass')) + .width('40%') + .interpolation(ImageInterpolation.Medium) + .borderWidth(1) + .overlay("Interpolation.Medium", { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + .margin(10) + Image($r('app.media.grass')) + .width('40%') + .interpolation(ImageInterpolation.High) + .borderWidth(1) + .overlay("Interpolation.High", { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + .margin(10) + }.width('100%') + .justifyContent(FlexAlign.Center) + } + .height('100%') + } +} +``` + + + + +### 设置图片é‡å¤æ ·å¼ + +通过objectRepeat属性设置图片的é‡å¤æ ·å¼æ–¹å¼ï¼Œé‡å¤æ ·å¼è¯·å‚考枚举说明。 + + +```ts +@Entry +@Component +struct MyComponent { + build() { + Column({ space: 10 }) { + Row({ space: 5 }) { + Image($r('app.media.ic_public_favor_filled_1')) + .width(110) + .height(115) + .border({ width: 1 }) + .objectRepeat(ImageRepeat.XY) + .objectFit(ImageFit.ScaleDown) + // 在水平轴和竖直轴上åŒæ—¶é‡å¤ç»˜åˆ¶å›¾ç‰‡ + .overlay('ImageRepeat.XY', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + Image($r('app.media.ic_public_favor_filled_1')) + .width(110) + .height(115) + .border({ width: 1 }) + .objectRepeat(ImageRepeat.Y) + .objectFit(ImageFit.ScaleDown) + // åªåœ¨ç«–直轴上é‡å¤ç»˜åˆ¶å›¾ç‰‡ + .overlay('ImageRepeat.Y', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + Image($r('app.media.ic_public_favor_filled_1')) + .width(110) + .height(115) + .border({ width: 1 }) + .objectRepeat(ImageRepeat.X) + .objectFit(ImageFit.ScaleDown) + // åªåœ¨æ°´å¹³è½´ä¸Šé‡å¤ç»˜åˆ¶å›¾ç‰‡ + .overlay('ImageRepeat.X', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + } + }.height(150).width('100%').padding(8) + } +} +``` + + + + +### è®¾ç½®å›¾ç‰‡æ¸²æŸ“æ¨¡å¼ + +通过renderMode属性设置图片的渲染模å¼ä¸ºåŽŸè‰²æˆ–黑白。 + + +```ts +@Entry +@Component +struct MyComponent { + build() { + Column({ space: 10 }) { + Row({ space: 50 }) { + Image($r('app.media.example')) + // 设置图片的渲染模å¼ä¸ºåŽŸè‰² + .renderMode(ImageRenderMode.Original) + .width(100) + .height(100) + .border({ width: 1 }) + // overlayæ˜¯é€šç”¨å±žæ€§ï¼Œç”¨äºŽåœ¨ç»„ä»¶ä¸Šæ˜¾ç¤ºè¯´æ˜Žæ–‡å— + .overlay('Original', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + Image($r('app.media.example')) + // 设置图片的渲染模å¼ä¸ºé»‘白 + .renderMode(ImageRenderMode.Template) + .width(100) + .height(100) + .border({ width: 1 }) + .overlay('Template', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) + } + }.height(150).width('100%').padding({ top: 20,right: 10 }) + } +} +``` + + + + +### 设置图片解ç 尺寸 + +通过sourceSize属性设置图片解ç 尺寸,é™ä½Žå›¾ç‰‡çš„分辨率。 + + +```ts +@Entry +@Component +struct Index { + build() { + Column() { + Row({ space: 20 }) { + Image($r('app.media.example')) + .sourceSize({ + width: 150, + height: 150 + }) + .objectFit(ImageFit.ScaleDown) + .width('25%') + .aspectRatio(1) + .border({ width: 1 }) + .overlay('width:150 height:150', { align: Alignment.Bottom, offset: { x: 0, y: 40 } }) + Image($r('app.media.example')) + .sourceSize({ + width: 400, + height: 400 + }) + .objectFit(ImageFit.ScaleDown) + .width('25%') + .aspectRatio(1) + .border({ width: 1 }) + .overlay('width:400 height:400', { align: Alignment.Bottom, offset: { x: 0, y: 40 } }) + }.height(150).width('100%').padding(20) + + } + } +} +``` + + + + +### ä¸ºå›¾ç‰‡æ·»åŠ æ»¤é•œæ•ˆæžœ + +通过colorFilter修改图片的åƒç´ é¢œè‰²ï¼Œä¸ºå›¾ç‰‡æ·»åŠ æ»¤é•œã€‚ + + +```ts +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + Image($r('app.media.example')) + .width('40%') + .margin(10) + Image($r('app.media.example')) + .width('40%') + .colorFilter( + [1, 1, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0]) + .margin(10) + }.width('100%') + .justifyContent(FlexAlign.Center) + } + } +} +``` + + ### åŒæ¥åŠ 载图片 -- GitLab