• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.wallpaper (壁纸)
2
3壁纸管理服务是OpenHarmony中的系统服务,主要为系统提供壁纸管理服务能力,支持系统显示、设置、切换壁纸等功能。
4
5> **说明:**
6>
7> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9
10## 导入模块
11
12
13```ts
14import wallpaper from '@ohos.wallpaper';
15```
16## WallpaperResourceType<sup>10+</sup>
17
18定义壁纸资源的枚举类型。
19
20**系统能力**: SystemCapability.MiscServices.Wallpaper
21
22**系统接口**:此接口为系统接口。
23
24| 名称 | 值 |说明 |
25| -------- | -------- |-------- |
26| DEFAULT | 0 |默认为图片资源。 |
27| PICTURE | 1 |图片资源。 |
28| VIDEO | 2 |视频资源。 |
29| PACKAGE | 3 |包资源。 |
30
31
32## WallpaperType<sup>7+</sup>
33
34定义壁纸的枚举类型。
35
36**系统能力**: SystemCapability.MiscServices.Wallpaper
37
38| 名称 | 值 |说明 |
39| -------- | -------- |-------- |
40| WALLPAPER_SYSTEM | 0 |主屏幕壁纸标识。 |
41| WALLPAPER_LOCKSCREEN | 1 |锁屏壁纸标识。 |
42
43
44## RgbaColor<sup>(deprecated)</sup>
45
46定义壁纸颜色信息结构。
47
48> **说明:**
49>
50> 从 API version 7开始支持,从API version 9开始废弃。
51
52**系统能力**: SystemCapability.MiscServices.Wallpaper
53
54| 名称 | 类型 | 可读 | 可写 | 说明 |
55| -------- | -------- | -------- | -------- | -------- |
56| red | number | 是 | 是 | 表示红色值,范围为 0 到 255。 |
57| green | number | 是 | 是 | 表示绿色值,范围为 0 到 255。 |
58| blue | number | 是 | 是 | 表示蓝色值,范围为 0 到 255。 |
59| alpha | number | 是 | 是 | 表示 alpha 值,范围为 0 到 255。 |
60
61
62## wallpaper.setVideo<sup>10+</sup>
63
64setVideo(source: string, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
65
66将视频资源设置为桌面或锁屏的动态壁纸。使用callback异步回调。
67
68**需要权限**:ohos.permission.SET_WALLPAPER
69
70**系统能力**: SystemCapability.MiscServices.Wallpaper
71
72**系统接口**:此接口为系统接口。
73
74**参数:**
75
76| 参数名 | 类型 | 必填 | 说明 |
77| -------- | -------- | -------- | -------- |
78| source | string | 是 | mp4文件的Uri路径。 |
79| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
80| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,设置壁纸成功,error为undefined,否则返回error信息。 |
81
82**示例:**
83
84```ts
85import { BusinessError } from '@ohos.base';
86
87let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4";
88try {
89    wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
90        if (error) {
91            console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
92            return;
93        }
94        console.log(`success to setVideo.`);
95    });
96} catch (error) {
97    console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
98}
99```
100
101## wallpaper.setVideo<sup>10+</sup>
102
103setVideo(source: string, wallpaperType: WallpaperType): Promise&lt;void&gt;
104
105将视频资源设置为桌面或锁屏的动态壁纸。使用promise异步回调。
106
107**需要权限**:ohos.permission.SET_WALLPAPER
108
109**系统能力**: SystemCapability.MiscServices.Wallpaper
110
111**系统接口**:此接口为系统接口。
112
113**参数:**
114
115| 参数名 | 类型 | 必填 | 说明 |
116| -------- | -------- | -------- | -------- |
117| source | string | 是 | mp4文件的Uri路径。 |
118| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
119
120**返回值:**
121
122| 类型 | 说明 |
123| -------- | -------- |
124| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
125
126**示例:**
127
128```ts
129import { BusinessError } from '@ohos.base';
130
131let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4";
132try {
133    wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
134        console.log(`success to setVideo.`);
135    }).catch((error: BusinessError) => {
136        console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
137    });
138} catch (error) {
139    console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
140}
141```
142
143## wallpaper.setCustomWallpaper<sup>10+</sup>
144
145setCustomWallpaper(source: string, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
146
147将指定uri的内容设置为壁纸资源,仅当com.ohos.sceneboard存在时,支持使用该接口。使用callback异步回调。
148
149**需要权限**:ohos.permission.SET_WALLPAPER
150
151**系统能力**: SystemCapability.MiscServices.Wallpaper
152
153**系统接口**:此接口为系统接口。
154
155**参数:**
156
157| 参数名 | 类型 | 必填 | 说明 |
158| -------- | -------- | -------- | -------- |
159| source | string | 是 | 自定义壁纸的Uri路径。 |
160| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
161| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,设置壁纸成功,error为undefined,否则返回error信息。 |
162
163**示例:**
164
165```ts
166import { BusinessError } from '@ohos.base';
167
168let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip";
169try {
170    wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
171        if (error) {
172            console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
173            return;
174        }
175        console.log(`success to setCustomWallpaper.`);
176    });
177} catch (error) {
178    console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
179}
180
181```
182
183## wallpaper.setCustomWallpaper<sup>10+</sup>
184
185setCustomWallpaper(source: string, wallpaperType: WallpaperType): Promise&lt;void&gt;
186
187将指定uri的内容设置为壁纸资源,仅当com.ohos.sceneboard存在时,支持使用该接口。使用Promise异步回调。
188
189**需要权限**:ohos.permission.SET_WALLPAPER
190
191**系统能力**: SystemCapability.MiscServices.Wallpaper
192
193**系统接口**:此接口为系统接口。
194
195**参数:**
196
197| 参数名 | 类型 | 必填 | 说明 |
198| -------- | -------- | -------- | -------- |
199| source | string | 是 | 自定义壁纸的Uri路径。 |
200| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
201
202**返回值:**
203
204| 类型 | 说明 |
205| -------- | -------- |
206| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
207
208**示例:**
209
210```ts
211import { BusinessError } from '@ohos.base';
212
213let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip";
214try {
215    wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
216        console.log(`success to setCustomWallpaper.`);
217    }).catch((error: BusinessError) => {
218        console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
219    });
220} catch (error) {
221    console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
222}
223```
224
225## wallpaper.on('wallpaperChange')<sup>10+</sup>
226
227on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) =&gt; void): void
228
229订阅壁纸变化通知事件。
230
231**系统能力**: SystemCapability.MiscServices.Wallpaper
232
233**系统接口**:此接口为系统接口。
234
235**参数:**
236
237| 参数名 | 类型 | 必填 | 说明 |
238| -------- | -------- | -------- | -------- |
239| type | string | 是 | 事件回调类型。支持的事件为'wallpaperChange',完成壁纸切换后触发该事件。 |
240| callback | function | 是 | 壁纸变化触发该回调方法,返回壁纸类型和壁纸资源类型。<br/>- wallpaperType:壁纸类型。<br/>- resourceType:壁纸资源类型。<br/>- uri:壁纸资源地址。 |
241
242**示例:**
243
244```ts
245try {
246    let listener = (wallpaperType: wallpaper.WallpaperType, resourceType: wallpaper.WallpaperResourceType): void => {
247        console.log(`wallpaper color changed.`);
248    };
249    wallpaper.on('wallpaperChange', listener);
250} catch (error) {
251    console.error(`failed to on because: ${JSON.stringify(error)}`);
252}
253```
254
255## wallpaper.off('wallpaperChange')<sup>10+</sup>
256
257off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) =&gt; void): void
258
259取消订阅壁纸变化通知事件。
260
261**系统能力**: SystemCapability.MiscServices.Wallpaper
262
263**系统接口**:此接口为系统接口。
264
265**参数:**
266
267| 参数名 | 类型 | 必填 | 说明 |
268| -------- | -------- | -------- | -------- |
269| type | string | 是 | 事件回调类型。支持的事件为'wallpaperChange',完成壁纸切换后触发该事件。 |
270| callback | function | 否 |   表示要取消的壁纸变化回调,不填写该参数则取消订阅该type对应的所有回调。<br/>- wallpaperType:壁纸类型。<br/>- resourceType:壁纸资源类型。<br/>- uri:壁纸资源地址。 |
271
272**示例:**
273
274```ts
275let listener = (wallpaperType: wallpaper.WallpaperType, resourceType: wallpaper.WallpaperResourceType): void => {
276    console.log(`wallpaper color changed.`);
277};
278try {
279    wallpaper.on('wallpaperChange', listener);
280} catch (error) {
281    console.error(`failed to on because: ${JSON.stringify(error)}`);
282}
283
284try {
285    // 取消订阅listener
286    wallpaper.off('wallpaperChange', listener);
287} catch (error) {
288    console.error(`failed to off because: ${JSON.stringify(error)}`);
289}
290
291try {
292    // 取消所有'wallpaperChange'类型的订阅
293    wallpaper.off('wallpaperChange');
294} catch (error) {
295    console.error(`failed to off because: ${JSON.stringify(error)}`);
296}
297```
298
299## wallpaper.getColorsSync<sup>9+</sup>
300
301getColorsSync(wallpaperType: WallpaperType): Array&lt;RgbaColor&gt;
302
303获取指定类型壁纸的主要颜色信息。
304
305**系统能力**: SystemCapability.MiscServices.Wallpaper
306
307**系统接口**:此接口为系统接口。
308
309**参数:**
310
311| 参数名 | 类型 | 必填 | 说明 |
312| -------- | -------- | -------- | -------- |
313| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
314
315**返回值**:
316
317| 类型 | 说明 |
318| -------- | -------- |
319| Array&lt;[RgbaColor](#rgbacolor)&gt; | 返回壁纸的主要颜色信息。 |
320
321**示例**:
322
323```ts
324try {
325    let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
326    console.log(`success to getColorsSync: ${JSON.stringify(colors)}`);
327} catch (error) {
328    console.error(`failed to getColorsSync because: ${JSON.stringify(error)}`);
329}
330```
331
332## wallpaper.getMinHeightSync<sup>9+</sup>
333
334getMinHeightSync(): number
335
336获取壁纸的最小高度值。
337
338**系统能力**: SystemCapability.MiscServices.Wallpaper
339
340**系统接口**:此接口为系统接口。
341
342**返回值:**
343
344| 类型 | 说明 |
345| -------- | -------- |
346| number | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 |
347
348**示例:**
349
350```ts
351let minHeight = wallpaper.getMinHeightSync();
352```
353
354## wallpaper.getMinWidthSync<sup>9+</sup>
355
356getMinWidthSync(): number
357
358获取壁纸的最小宽度值。
359
360**系统能力**: SystemCapability.MiscServices.Wallpaper
361
362**系统接口**:此接口为系统接口。
363
364**返回值:**
365
366| 类型 | 说明 |
367| -------- | -------- |
368| number | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 |
369
370**示例:**
371
372```ts
373let minWidth = wallpaper.getMinWidthSync();
374```
375
376## wallpaper.restore<sup>9+</sup>
377
378restore(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
379
380移除指定类型的壁纸,恢复为默认显示的壁纸。使用callback异步回调。
381
382**需要权限**:ohos.permission.SET_WALLPAPER
383
384**系统能力**: SystemCapability.MiscServices.Wallpaper
385
386**系统接口**:此接口为系统接口。
387
388**参数:**
389
390| 参数名 | 类型 | 必填 | 说明 |
391| -------- | -------- | -------- | -------- |
392| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
393| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,移除壁纸成功,error为undefined,否则返回error信息。 |
394
395**示例:**
396
397```ts
398import { BusinessError } from '@ohos.base';
399
400wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
401    if (error) {
402        console.error(`failed to restore because: ${JSON.stringify(error)}`);
403        return;
404    }
405    console.log(`success to restore.`);
406});
407```
408
409## wallpaper.restore<sup>9+</sup>
410
411restore(wallpaperType: WallpaperType): Promise&lt;void&gt;
412
413移除指定类型的壁纸,恢复为默认显示的壁纸。使用promise异步回调。
414
415**需要权限**:ohos.permission.SET_WALLPAPER
416
417**系统能力**: SystemCapability.MiscServices.Wallpaper
418
419**系统接口**:此接口为系统接口。
420
421**参数:**
422
423| 参数名 | 类型 | 必填 | 说明 |
424| -------- | -------- | -------- | -------- |
425| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
426
427**返回值:**
428
429| 类型 | 说明 |
430| -------- | -------- |
431| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
432
433**示例:**
434
435```ts
436import { BusinessError } from '@ohos.base';
437
438wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
439    console.log(`success to restore.`);
440  }).catch((error: BusinessError) => {
441    console.error(`failed to restore because: ${JSON.stringify(error)}`);
442});
443```
444
445## wallpaper.setImage<sup>9+</sup>
446
447setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
448
449将指定资源设置为指定类型的壁纸。使用callback异步回调。
450
451**需要权限**:ohos.permission.SET_WALLPAPER
452
453**系统能力**: SystemCapability.MiscServices.Wallpaper
454
455**系统接口**:此接口为系统接口。
456
457**参数:**
458
459| 参数名 | 类型 | 必填 | 说明 |
460| -------- | -------- | -------- | -------- |
461| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
462| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
463| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,设置壁纸成功,error为undefined,否则返回error信息。 |
464
465**示例:**
466
467```ts
468import { BusinessError } from '@ohos.base';
469import image from '@ohos.multimedia.image';
470
471// source类型为string
472let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
473wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
474    if (error) {
475        console.error(`failed to setImage because: ${JSON.stringify(error)}`);
476        return;
477     }
478    console.log(`success to setImage.`);
479});
480
481// source类型为image.PixelMap
482let imageSource = image.createImageSource("file://" + wallpaperPath);
483let opts: image.DecodingOptions = {
484    desiredSize: {
485        height: 3648,
486        width: 2736
487    }
488};
489imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
490    wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
491        if (error) {
492            console.error(`failed to setImage because: ${JSON.stringify(error)}`);
493            return;
494        }
495        console.log(`success to setImage.`);
496    });
497}).catch((error: BusinessError) => {
498    console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`);
499});
500```
501
502## wallpaper.setImage<sup>9+</sup>
503
504setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
505
506将指定资源设置为指定类型的壁纸。使用promise异步回调。
507
508**需要权限**:ohos.permission.SET_WALLPAPER
509
510**系统能力**: SystemCapability.MiscServices.Wallpaper
511
512**系统接口**:此接口为系统接口。
513
514**参数:**
515
516| 参数名 | 类型 | 必填 | 说明 |
517| -------- | -------- | -------- | -------- |
518| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
519| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
520
521**返回值:**
522
523| 类型 | 说明 |
524| -------- | -------- |
525| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
526
527**示例:**
528
529```ts
530import { BusinessError } from '@ohos.base';
531import image from '@ohos.multimedia.image';
532
533// source类型为string
534let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
535wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
536    console.log(`success to setImage.`);
537}).catch((error: BusinessError) => {
538    console.error(`failed to setImage because: ${JSON.stringify(error)}`);
539});
540
541// source类型为image.PixelMap
542let imageSource = image.createImageSource("file://" + wallpaperPath);
543let opts: image.DecodingOptions = {
544    desiredSize: {
545        height: 3648,
546        width: 2736
547    }
548};
549imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
550    wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
551        console.log(`success to setImage.`);
552    }).catch((error: BusinessError) => {
553        console.error(`failed to setImage because: ${JSON.stringify(error)}`);
554    });
555}).catch((error: BusinessError) => {
556    console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`);
557});
558```
559
560## wallpaper.getImage<sup>9+</sup>
561
562getImage(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;
563
564获取壁纸图片的像素图。使用callback异步回调。
565
566**需要权限**:ohos.permission.GET_WALLPAPER
567
568**系统能力**: SystemCapability.MiscServices.Wallpaper
569
570**系统接口**:此接口为系统接口。
571
572**参数:**
573
574| 参数名 | 类型 | 必填 | 说明 |
575| -------- | -------- | -------- | -------- |
576| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
577| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | 是 | 回调函数,调用成功则返回壁纸图片的像素图对象,调用失败则返回error信息。 |
578
579**示例:**
580
581```ts
582import { BusinessError } from '@ohos.base';
583
584wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: image.PixelMap) => {
585    if (error) {
586        console.error(`failed to getImage because: ${JSON.stringify(error)}`);
587        return;
588    }
589    console.log(`success to getImage: ${JSON.stringify(data)}`);
590});
591```
592
593
594## wallpaper.getImage<sup>9+</sup>
595
596getImage(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;
597
598获取壁纸图片的像素图。使用promise异步回调。
599
600**需要权限**:ohos.permission.GET_WALLPAPER
601
602**系统能力**: SystemCapability.MiscServices.Wallpaper
603
604**系统接口**:此接口为系统接口。
605
606**参数:**
607
608| 参数名 | 类型 | 必填 | 说明 |
609| -------- | -------- | -------- | -------- |
610| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
611
612**返回值:**
613
614| 类型 | 说明 |
615| -------- | -------- |
616| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | 调用成功则返回壁纸图片的像素图对象,调用失败则返回error信息。 |
617
618**示例:**
619
620```ts
621import { BusinessError } from '@ohos.base';
622
623wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: image.PixelMap) => {
624    console.log(`success to getImage: ${JSON.stringify(data)}`);
625  }).catch((error: BusinessError) => {
626    console.error(`failed to getImage because: ${JSON.stringify(error)}`);
627});
628```
629
630## wallpaper.on('colorChange')<sup>(deprecated)</sup>
631
632on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
633
634订阅壁纸颜色变化结果上报事件。
635
636> **说明:**
637>
638> 从 API version 7开始支持,从API version 9开始废弃。
639
640**系统能力**: SystemCapability.MiscServices.Wallpaper
641
642**参数:**
643
644| 参数名 | 类型 | 必填 | 说明 |
645| -------- | -------- | -------- | -------- |
646| type | string | 是 | 取值为'colorChange',表示壁纸颜色变化结果上报事件。 |
647| callback | function | 是 | 壁纸颜色变化触发该回调方法,返回壁纸类型和壁纸的主要颜色信息。<br/>- colors<br/>  壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。<br/>- wallpaperType<br/>  壁纸类型。 |
648
649**示例:**
650
651```ts
652try {
653    let listener = (colors: Array<wallpaper.RgbaColor>, wallpaperType: wallpaper.WallpaperType): void => {
654        console.log(`wallpaper color changed.`);
655    };
656    wallpaper.on('colorChange', listener);
657} catch (error) {
658    console.error(`failed to on because: ${JSON.stringify(error)}`);
659}
660```
661
662## wallpaper.off('colorChange')<sup>(deprecated)</sup>
663
664off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
665
666取消订阅壁纸颜色变化结果上报事件。
667
668> **说明:**
669>
670> 从 API version 7开始支持,从API version 9开始废弃。
671
672**系统能力**: SystemCapability.MiscServices.Wallpaper
673
674**参数:**
675
676| 参数名 | 类型 | 必填 | 说明 |
677| -------- | -------- | -------- | -------- |
678| type | string | 是 | 取值为'colorChange',表示取消订阅壁纸颜色变化结果上报事件。 |
679| callback | function | 否 |   表示要取消的壁纸颜色变化的回调,不填写该参数则取消订阅该type对应的所有回调。<br/>- colors<br/>  壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。<br/>- wallpaperType<br/>  壁纸类型。 |
680
681**示例:**
682
683```ts
684let listener = (colors: Array<wallpaper.RgbaColor>, wallpaperType: wallpaper.WallpaperType): void => {
685    console.log(`wallpaper color changed.`);
686};
687try {
688    wallpaper.on('colorChange', listener);
689} catch (error) {
690    console.error(`failed to on because: ${JSON.stringify(error)}`);
691}
692
693try {
694    // 取消订阅listener
695    wallpaper.off('colorChange', listener);
696} catch (error) {
697    console.error(`failed to off because: ${JSON.stringify(error)}`);
698}
699
700try {
701    // 取消所有'colorChange'类型的订阅
702    wallpaper.off('colorChange');
703} catch (error) {
704    console.error(`failed to off because: ${JSON.stringify(error)}`);
705}
706```
707
708## wallpaper.getColors<sup>(deprecated)</sup>
709
710getColors(wallpaperType: WallpaperType, callback: AsyncCallback&lt;Array&lt;RgbaColor&gt;&gt;): void
711
712获取指定类型壁纸的主要颜色信息。
713
714> **说明:**
715>
716> 从 API version 7开始支持,从API version 9开始废弃。
717
718**系统能力**: SystemCapability.MiscServices.Wallpaper
719
720**参数:**
721
722| 参数名 | 类型 | 必填 | 说明 |
723| -------- | -------- | -------- | -------- |
724| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
725| callback | AsyncCallback&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | 是 | 回调函数,返回壁纸的主要颜色信息。 |
726
727**示例:**
728
729```ts
730import { BusinessError } from '@ohos.base';
731
732wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: Array<wallpaper.RgbaColor>) => {
733    if (error) {
734        console.error(`failed to getColors because: ${JSON.stringify(error)}`);
735        return;
736    }
737    console.log(`success to getColors: ${JSON.stringify(data)}`);
738});
739```
740
741## wallpaper.getColors<sup>(deprecated)</sup>
742
743getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;
744
745获取指定类型壁纸的主要颜色信息。
746
747> **说明:**
748>
749> 从 API version 7开始支持,从API version 9开始废弃。
750
751**系统能力**: SystemCapability.MiscServices.Wallpaper
752
753**参数:**
754
755| 参数名 | 类型 | 必填 | 说明 |
756| -------- | -------- | -------- | -------- |
757| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
758
759**返回值:**
760
761| 类型 | 说明 |
762| -------- | -------- |
763| Promise&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | 返回壁纸的主要颜色信息。 |
764
765**示例:**
766
767```ts
768import { BusinessError } from '@ohos.base';
769
770wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: Array<wallpaper.RgbaColor>) => {
771    console.log(`success to getColors: ${JSON.stringify(data)}`);
772  }).catch((error: BusinessError) => {
773    console.error(`failed to getColors because: ${JSON.stringify(error)}`);
774});
775```
776
777## wallpaper.getId<sup>(deprecated)</sup>
778
779getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
780
781获取指定类型壁纸的ID。
782
783> **说明:**
784>
785> 从 API version 7开始支持,从API version 9开始废弃。
786
787**系统能力**: SystemCapability.MiscServices.Wallpaper
788
789**参数:**
790
791| 参数名 | 类型 | 必填 | 说明 |
792| -------- | -------- | -------- | -------- |
793| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
794| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回壁纸的ID。如果配置了指定类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1到(2^31-1)。 |
795
796**示例:**
797
798```ts
799import { BusinessError } from '@ohos.base';
800
801wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: Number) => {
802    if (error) {
803        console.error(`failed to getId because: ${JSON.stringify(error)}`);
804        return;
805    }
806    console.log(`success to getId: ${JSON.stringify(data)}`);
807});
808```
809
810## wallpaper.getId<sup>(deprecated)</sup>
811
812getId(wallpaperType: WallpaperType): Promise&lt;number&gt;
813
814获取指定类型壁纸的ID。
815
816> **说明:**
817>
818> 从 API version 7开始支持,从API version 9开始废弃。
819
820**系统能力**: SystemCapability.MiscServices.Wallpaper
821
822**参数:**
823
824| 参数名 | 类型 | 必填 | 说明 |
825| -------- | -------- | -------- | -------- |
826| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
827
828**返回值:**
829
830| 类型 | 说明 |
831| -------- | -------- |
832| Promise&lt;number&gt; | 壁纸的ID。如果配置了这种壁纸类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1到(2^31-1)。 |
833
834**示例:**
835
836```ts
837import { BusinessError } from '@ohos.base';
838
839wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: Number) => {
840    console.log(`success to getId: ${JSON.stringify(data)}`);
841  }).catch((error: BusinessError) => {
842    console.error(`failed to getId because: ${JSON.stringify(error)}`);
843});
844```
845
846## wallpaper.getMinHeight<sup>(deprecated)</sup>
847
848getMinHeight(callback: AsyncCallback&lt;number&gt;): void
849
850获取壁纸的最小高度值。
851
852> **说明:**
853>
854> 从 API version 7开始支持,从API version 9开始废弃。
855
856**系统能力**: SystemCapability.MiscServices.Wallpaper
857
858**参数:**
859
860| 参数名 | 类型 | 必填 | 说明 |
861| -------- | -------- | -------- | -------- |
862| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 |
863
864**示例:**
865
866```ts
867import { BusinessError } from '@ohos.base';
868
869wallpaper.getMinHeight((error: BusinessError, data: Number) => {
870    if (error) {
871        console.error(`failed to getMinHeight because: ${JSON.stringify(error)}`);
872        return;
873    }
874    console.log(`success to getMinHeight: ${JSON.stringify(data)}`);
875});
876```
877
878## wallpaper.getMinHeight<sup>(deprecated)</sup>
879
880getMinHeight(): Promise&lt;number&gt;
881
882获取壁纸的最小高度值。
883
884> **说明:**
885>
886> 从 API version 7开始支持,从API version 9开始废弃。
887
888**系统能力**: SystemCapability.MiscServices.Wallpaper
889
890**返回值:**
891
892| 类型 | 说明 |
893| -------- | -------- |
894| Promise&lt;number&gt; | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 |
895
896**示例:**
897
898```ts
899import { BusinessError } from '@ohos.base';
900
901wallpaper.getMinHeight().then((data: Number) => {
902    console.log(`success to getMinHeight: ${JSON.stringify(data)}`);
903}).catch((error: BusinessError) => {
904    console.error(`failed to getMinHeight because: ${JSON.stringify(error)}`);
905});
906```
907
908## wallpaper.getMinWidth<sup>(deprecated)</sup>
909
910getMinWidth(callback: AsyncCallback&lt;number&gt;): void
911
912获取壁纸的最小宽度值。
913
914> **说明:**
915>
916> 从 API version 7开始支持,从API version 9开始废弃。
917
918**系统能力**: SystemCapability.MiscServices.Wallpaper
919
920**参数:**
921
922| 参数名 | 类型 | 必填 | 说明 |
923| -------- | -------- | -------- | -------- |
924| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 |
925
926**示例:**
927
928```ts
929import { BusinessError } from '@ohos.base';
930
931wallpaper.getMinWidth((error: BusinessError, data: Number) => {
932    if (error) {
933        console.error(`failed to getMinWidth because: ${JSON.stringify(error)}`);
934        return;
935    }
936    console.log(`success to getMinWidth: ${JSON.stringify(data)}`);
937});
938```
939
940## wallpaper.getMinWidth<sup>(deprecated)</sup>
941
942getMinWidth(): Promise&lt;number&gt;
943
944获取壁纸的最小宽度值。
945
946> **说明:**
947>
948> 从 API version 7开始支持,从API version 9开始废弃。
949
950**系统能力**: SystemCapability.MiscServices.Wallpaper
951
952**返回值:**
953
954| 类型 | 说明 |
955| -------- | -------- |
956| Promise&lt;number&gt; | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 |
957
958**示例:**
959
960```ts
961import { BusinessError } from '@ohos.base';
962
963wallpaper.getMinWidth().then((data: Number) => {
964    console.log(`success to getMinWidth: ${JSON.stringify(data)}`);
965  }).catch((error: BusinessError) => {
966    console.error(`failed to getMinWidth because: ${JSON.stringify(error)}`);
967});
968```
969
970## wallpaper.isChangePermitted<sup>(deprecated)</sup>
971
972isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void
973
974是否允许应用改变当前用户的壁纸。
975
976> **说明:**
977>
978> 从 API version 7开始支持,从API version 9开始废弃。
979
980**系统能力**: SystemCapability.MiscServices.Wallpaper
981
982**参数:**
983
984| 参数名 | 类型 | 必填 | 说明 |
985| -------- | -------- | -------- | -------- |
986| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 |
987
988**示例:**
989
990```ts
991import { BusinessError } from '@ohos.base';
992
993wallpaper.isChangePermitted((error: BusinessError, data: Boolean) => {
994    if (error) {
995        console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`);
996        return;
997    }
998    console.log(`success to isChangePermitted: ${JSON.stringify(data)}`);
999});
1000```
1001
1002## wallpaper.isChangePermitted<sup>(deprecated)</sup>
1003
1004isChangePermitted(): Promise&lt;boolean&gt;
1005
1006是否允许应用改变当前用户的壁纸。
1007
1008> **说明:**
1009>
1010> 从 API version 7开始支持,从API version 9开始废弃。
1011
1012**系统能力**: SystemCapability.MiscServices.Wallpaper
1013
1014**返回值:**
1015
1016| 类型 | 说明 |
1017| -------- | -------- |
1018| Promise&lt;boolean&gt; | 返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 |
1019
1020**示例:**
1021
1022```ts
1023import { BusinessError } from '@ohos.base';
1024
1025wallpaper.isChangePermitted().then((data: Boolean) => {
1026    console.log(`success to isChangePermitted: ${JSON.stringify(data)}`);
1027}).catch((error: BusinessError) => {
1028    console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`);
1029});
1030```
1031
1032## wallpaper.isOperationAllowed<sup>(deprecated)</sup>
1033
1034isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void
1035
1036是否允许用户设置壁纸。
1037
1038> **说明:**
1039>
1040> 从 API version 7开始支持,从API version 9开始废弃。
1041
1042**系统能力**: SystemCapability.MiscServices.Wallpaper
1043
1044**参数:**
1045
1046| 参数名 | 类型 | 必填 | 说明 |
1047| -------- | -------- | -------- | -------- |
1048| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 |
1049
1050**示例:**
1051
1052```ts
1053import { BusinessError } from '@ohos.base';
1054
1055wallpaper.isChangePermitted().then((data: Boolean) => {
1056    console.log(`success to isChangePermitted: ${JSON.stringify(data)}`);
1057}).catch((error: BusinessError) => {
1058    console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`);
1059});
1060```
1061
1062## wallpaper.isOperationAllowed<sup>(deprecated)</sup>
1063
1064isOperationAllowed(): Promise&lt;boolean&gt;
1065
1066是否允许用户设置壁纸。
1067
1068> **说明:**
1069>
1070> 从 API version 7开始支持,从API version 9开始废弃。
1071
1072**系统能力**: SystemCapability.MiscServices.Wallpaper
1073
1074**返回值:**
1075
1076| 类型 | 说明 |
1077| -------- | -------- |
1078| Promise&lt;boolean&gt; | 异步回调函数,返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 |
1079
1080**示例:**
1081
1082```ts
1083import { BusinessError } from '@ohos.base';
1084
1085wallpaper.isOperationAllowed().then((data: Boolean) => {
1086    console.log(`success to isOperationAllowed: ${JSON.stringify(data)}`);
1087  }).catch((error: BusinessError) => {
1088    console.error(`failed to isOperationAllowed because: ${JSON.stringify(error)}`);
1089});
1090```
1091
1092## wallpaper.reset<sup>(deprecated)</sup>
1093
1094reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
1095
1096移除指定类型的壁纸,恢复为默认显示的壁纸。
1097
1098> **说明:**
1099>
1100> 从 API version 7开始支持,从API version 9开始废弃。
1101
1102**需要权限**:ohos.permission.SET_WALLPAPER
1103
1104**系统能力**: SystemCapability.MiscServices.Wallpaper
1105
1106**参数:**
1107
1108| 参数名 | 类型 | 必填 | 说明 |
1109| -------- | -------- | -------- | -------- |
1110| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1111| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,移除壁纸成功,error为undefined,否则返回error信息。 |
1112
1113**示例:**
1114
1115```ts
1116import { BusinessError } from '@ohos.base';
1117
1118wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
1119    if (error) {
1120        console.error(`failed to reset because: ${JSON.stringify(error)}`);
1121        return;
1122    }
1123    console.log(`success to reset.`);
1124});
1125```
1126
1127## wallpaper.reset<sup>(deprecated)</sup>
1128
1129reset(wallpaperType: WallpaperType): Promise&lt;void&gt;
1130
1131移除指定类型的壁纸,恢复为默认显示的壁纸。
1132
1133> **说明:**
1134>
1135> 从 API version 7开始支持,从API version 9开始废弃。
1136
1137**需要权限**:ohos.permission.SET_WALLPAPER
1138
1139**系统能力**: SystemCapability.MiscServices.Wallpaper
1140
1141**参数:**
1142
1143| 参数名 | 类型 | 必填 | 说明 |
1144| -------- | -------- | -------- | -------- |
1145| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1146
1147**返回值:**
1148
1149| 类型 | 说明 |
1150| -------- | -------- |
1151| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1152
1153**示例:**
1154
1155```ts
1156import { BusinessError } from '@ohos.base';
1157
1158wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
1159    console.log(`success to reset.`);
1160}).catch((error: BusinessError) => {
1161    console.error(`failed to reset because: ${JSON.stringify(error)}`);
1162});
1163```
1164
1165## wallpaper.setWallpaper<sup>(deprecated)</sup>
1166
1167setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
1168
1169将指定资源设置为指定类型的壁纸。
1170
1171> **说明:**
1172>
1173> 从 API version 7开始支持,从API version 9开始废弃。
1174
1175**需要权限**:ohos.permission.SET_WALLPAPER
1176
1177**系统能力**: SystemCapability.MiscServices.Wallpaper
1178
1179**参数:**
1180
1181| 参数名 | 类型 | 必填 | 说明 |
1182| -------- | -------- | -------- | -------- |
1183| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
1184| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1185| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,设置壁纸成功,error为undefined,否则返回error信息。 |
1186
1187**示例:**
1188
1189```ts
1190import { BusinessError } from '@ohos.base';
1191import image from '@ohos.multimedia.image';
1192
1193// source类型为string
1194let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
1195wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
1196    if (error) {
1197        console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
1198       return;
1199       }
1200    console.log(`success to setWallpaper.`);
1201});
1202
1203// source类型为image.PixelMap
1204let imageSource = image.createImageSource("file://" + wallpaperPath);
1205let opts: image.DecodingOptions = {
1206    desiredSize: {
1207        height: 3648,
1208        width: 2736
1209    }
1210};
1211imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
1212    wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => {
1213        if (error) {
1214            console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
1215            return;
1216        }
1217        console.log(`success to setWallpaper.`);
1218    });
1219}).catch((error: BusinessError) => {
1220    console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`);
1221});
1222```
1223
1224## wallpaper.setWallpaper<sup>(deprecated)</sup>
1225
1226setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
1227
1228将指定资源设置为指定类型的壁纸。
1229
1230> **说明:**
1231>
1232> 从 API version 7开始支持,从API version 9开始废弃。
1233
1234**需要权限**:ohos.permission.SET_WALLPAPER
1235
1236**系统能力**: SystemCapability.MiscServices.Wallpaper
1237
1238**参数:**
1239
1240| 参数名 | 类型 | 必填 | 说明 |
1241| -------- | -------- | -------- | -------- |
1242| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
1243| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1244
1245**返回值:**
1246
1247| 类型 | 说明 |
1248| -------- | -------- |
1249| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1250
1251**示例:**
1252
1253```ts
1254import { BusinessError } from '@ohos.base';
1255import image from '@ohos.multimedia.image';
1256
1257// source类型为string
1258let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
1259wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
1260    console.log(`success to setWallpaper.`);
1261  }).catch((error: BusinessError) => {
1262    console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
1263});
1264
1265// source类型为image.PixelMap
1266let imageSource = image.createImageSource("file://" + wallpaperPath);
1267let opts: image.DecodingOptions = {
1268    desiredSize: {
1269        height: 3648,
1270        width: 2736
1271    }
1272};
1273imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
1274    wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
1275        console.log(`success to setWallpaper.`);
1276    }).catch((error: BusinessError) => {
1277        console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
1278    });
1279  }).catch((error: BusinessError) => {
1280    console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`);
1281});
1282```
1283
1284
1285## wallpaper.getFile<sup>(deprecated)</sup>
1286
1287getFile(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
1288
1289获取指定类型的壁纸文件。
1290
1291> **说明:**
1292>
1293> 从 API version 8开始支持,从API version 9开始废弃。
1294
1295**需要权限**:ohos.permission.GET_WALLPAPER
1296
1297**系统能力**: SystemCapability.MiscServices.Wallpaper
1298
1299**参数:**
1300
1301| 参数名 | 类型 | 必填 | 说明 |
1302| -------- | -------- | -------- | -------- |
1303| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1304| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 |
1305
1306**示例:**
1307
1308```ts
1309import { BusinessError } from '@ohos.base';
1310
1311wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: number) => {
1312    if (error) {
1313        console.error(`failed to getFile because: ${JSON.stringify(error)}`);
1314        return;
1315    }
1316    console.log(`success to getFile: ${JSON.stringify(data)}`);
1317});
1318```
1319
1320## wallpaper.getFile<sup>(deprecated)</sup>
1321
1322getFile(wallpaperType: WallpaperType): Promise&lt;number&gt;
1323
1324获取指定类型的壁纸文件。
1325
1326> **说明:**
1327>
1328> 从 API version 8开始支持,从API version 9开始废弃。
1329
1330**需要权限**:ohos.permission.GET_WALLPAPER
1331
1332**系统能力**: SystemCapability.MiscServices.Wallpaper
1333
1334**参数:**
1335
1336| 参数名 | 类型 | 必填 | 说明 |
1337| -------- | -------- | -------- | -------- |
1338| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1339
1340**返回值:**
1341
1342| 类型 | 说明 |
1343| -------- | -------- |
1344| Promise&lt;number&gt; | 调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 |
1345
1346**示例:**
1347
1348```ts
1349import { BusinessError } from '@ohos.base';
1350
1351wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: number) => {
1352    console.log(`success to getFile: ${JSON.stringify(data)}`);
1353  }).catch((error: BusinessError) => {
1354    console.error(`failed to getFile because: ${JSON.stringify(error)}`);
1355});
1356
1357```
1358
1359## wallpaper.getPixelMap<sup>(deprecated)</sup>
1360
1361getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;
1362
1363获取壁纸图片的像素图。
1364
1365> **说明:**
1366>
1367> 从 API version 7开始支持,从API version 9开始废弃。
1368
1369**需要权限**:ohos.permission.GET_WALLPAPER
1370
1371**系统能力**: SystemCapability.MiscServices.Wallpaper
1372
1373**系统接口**:此接口为系统接口。
1374
1375**参数:**
1376
1377| 参数名 | 类型 | 必填 | 说明 |
1378| -------- | -------- | -------- | -------- |
1379| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1380| callback | AsyncCallback&lt;image.PixelMap&gt; | 是 | 回调函数,调用成功则返回壁纸图片的像素图对象,调用失败则返回error信息。 |
1381
1382**示例:**
1383
1384```ts
1385import { BusinessError } from '@ohos.base';
1386
1387wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: image.PixelMap) => {
1388    if (error) {
1389        console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`);
1390        return;
1391    }
1392    console.log(`success to getPixelMap : ${JSON.stringify(data)}`);
1393  });
1394```
1395
1396## wallpaper.getPixelMap<sup>(deprecated)</sup>
1397
1398getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;
1399
1400获取壁纸图片的像素图。
1401
1402> **说明:**
1403>
1404> 从 API version 7开始支持,从API version 9开始废弃。
1405
1406**需要权限**:ohos.permission.GET_WALLPAPER
1407
1408**系统能力**: SystemCapability.MiscServices.Wallpaper
1409
1410**系统接口**:此接口为系统接口。
1411
1412**参数:**
1413
1414| 参数名 | 类型 | 必填 | 说明 |
1415| -------- | -------- | -------- | -------- |
1416| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 |
1417
1418**返回值:**
1419
1420| 类型 | 说明 |
1421| -------- | -------- |
1422| Promise&lt;image.PixelMap&gt; | 调用成功则返回壁纸图片的像素图对象,调用失败则返回error信息。 |
1423
1424**示例:**
1425
1426```ts
1427import { BusinessError } from '@ohos.base';
1428
1429wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: image.PixelMap) => {
1430    console.log(`success to getPixelMap : ${JSON.stringify(data)}`);
1431  }).catch((error: BusinessError) => {
1432    console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`);
1433});
1434```
1435