1# 编辑图片EXIF信息
2
3图片工具当前主要提供图片EXIF信息的读取与编辑能力。
4
5EXIF(Exchangeable image file format)是专门为数码相机的照片设定的文件格式,可以记录数码照片的属性信息和拍摄数据。当前仅支持JPEG格式图片。
6
7在图库等应用中,需要查看或修改数码照片的EXIF信息。由于摄像机的手动镜头的参数无法自动写入到EXIF信息中或者因为相机断电等原因经常会导致拍摄时间出错,这时候就需要手动修改错误的EXIF数据,即可使用本功能。
8
9OpenHarmony目前仅支持对部分EXIF信息的查看和修改,具体支持的范围请参见:[Exif信息](../../reference/apis-image-kit/js-apis-image.md#propertykey7)。
10
11## 开发步骤
12
13EXIF信息的读取与编辑相关API的详细介绍请参见[API参考](../../reference/apis-image-kit/js-apis-image.md#getimageproperty11)。
14
151. 获取图片,创建图片源ImageSource。
16
17   ```ts
18   // 导入相关模块包
19   import { image } from '@kit.ImageKit';
20
21   // 获取沙箱路径创建ImageSource
22   const fd : number = 0; // 获取需要被处理的图片的fd
23   const imageSourceApi : image.ImageSource = image.createImageSource(fd);
24   ```
25
262. 读取、编辑EXIF信息。
27
28    ```ts
29    import { BusinessError } from '@kit.BasicServicesKit';
30    // 读取EXIF信息,BitsPerSample为每个像素比特数
31    let options : image.ImagePropertyOptions = { index: 0, defaultValue: '9999' }
32    imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options).then((data : string) => {
33        console.log('Succeeded in getting the value of the specified attribute key of the image.');
34    }).catch((error : BusinessError) => {
35        console.error('Failed to get the value of the specified attribute key of the image.');
36    })
37
38    // 编辑EXIF信息
39    imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => {
40        imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width : string) => {
41            console.info('The new imageWidth is ' + width);
42        }).catch((error : BusinessError) => {
43            console.error('Failed to get the Image Width.');
44        })
45    }).catch((error : BusinessError) => {
46        console.error('Failed to modify the Image Width');
47    })
48    ```
49