• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import router from '@ohos.router'
17import { Logger, FileManager } from '@ohos/feature-file-manager'
18
19@Entry
20@Component
21struct ImagePreview {
22  private params = router.getParams() as Record<string, Object>;
23  @State imagePixelMap: PixelMap | null = null;
24  fileName: string = this.params.imageFileName as string
25
26  async aboutToAppear() {
27    this.fileName = this.params.imageFileName as string
28    Logger.debug('fileName: ' + this.fileName)
29    let file = await FileManager.getFileAssetsByName(getContext(this), this.fileName)
30    this.imagePixelMap = await FileManager.getPixelMapByFileAsset(file)
31    if (this.imagePixelMap != undefined)
32      Logger.debug('pixel size: ' + this.imagePixelMap.getPixelBytesNumber())
33  }
34
35  build() {
36    Column() {
37      Row() {
38        Image($r('app.media.back'))
39          .id('imageBack')
40          .width(36)
41          .height(36)
42          .objectFit(ImageFit.Fill)
43          .alignSelf(ItemAlign.Start)
44
45        Text(this.fileName)
46          .fontSize(24)
47          .margin({ left: 10 })
48          .fontWeight(FontWeight.Bold)
49          .fontColor($r('app.color.black'))
50      }
51      .width('100%')
52      .margin({ top: 10 })
53      .onClick(() => {
54        router.back()
55      })
56
57      Image(this.imagePixelMap)
58        .objectFit(ImageFit.Fill)
59        .alignSelf(ItemAlign.Start)
60        .scale({ x: 0.9, y: 0.9 })
61    }
62    .height('100%')
63    .backgroundColor($r('app.color.white'))
64    .padding(20)
65  }
66}