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 @State imagePixelMap: PixelMap = undefined 23 fileName: string = router.getParams()['imageFileName'] 24 25 async aboutToAppear() { 26 this.fileName = router.getParams()['imageFileName'] 27 Logger.debug('fileName: ' + this.fileName) 28 let file = await FileManager.getFileAssetsByName(getContext(this), this.fileName) 29 this.imagePixelMap = await FileManager.getPixelMapByFileAsset(file) 30 Logger.debug('pixel size: ' + this.imagePixelMap.getPixelBytesNumber()) 31 } 32 33 build() { 34 Column() { 35 Row() { 36 Image($r('app.media.back')) 37 .width(36) 38 .height(36) 39 .objectFit(ImageFit.Fill) 40 .alignSelf(ItemAlign.Start) 41 42 Text(this.fileName) 43 .fontSize(24) 44 .margin({ left: 10 }) 45 .fontWeight(FontWeight.Bold) 46 .fontColor($r('app.color.black')) 47 } 48 .width('100%') 49 .margin({ top: 10 }) 50 .onClick(() => { 51 router.back() 52 }) 53 54 Image(this.imagePixelMap) 55 .objectFit(ImageFit.Fill) 56 .alignSelf(ItemAlign.Start) 57 .scale({ x: 0.9, y: 0.9 }) 58 } 59 .height('100%') 60 .backgroundColor($r('app.color.white')) 61 .padding(20) 62 } 63}