1# @ohos.wallpaper (Wallpaper) (System API) 2 3The **wallpaper** module provides APIs for switching between wallpapers. Since API version 9, the APIs of this module function as system APIs, and only system applications are allowed to switch between wallpapers. Applications that use the wallpaper, for example, the home screen, need to subscribe to wallpaper changes and update the wallpaper accordingly. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.wallpaper (Wallpaper)](js-apis-wallpaper.md). 9 10 11## Modules to Import 12 13 14```ts 15import { wallpaper } from '@kit.BasicServicesKit'; 16``` 17## WallpaperResourceType<sup>10+</sup> 18 19Enumerates the types of wallpaper resources. 20 21**System capability**: SystemCapability.MiscServices.Wallpaper 22 23**System API**: This is a system API. 24 25| Name| Value|Description| 26| -------- | -------- |-------- | 27| DEFAULT | 0 |Default type (image resource).| 28| PICTURE | 1 |Image resource.| 29| VIDEO | 2 |Video resource.| 30| PACKAGE | 3 |Package resource.| 31 32## wallpaper.setVideo<sup>10+</sup> 33 34setVideo(source: string, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 35 36Sets a video resource as the home screen wallpaper or lock screen wallpaper. This API uses an asynchronous callback to return the result. 37 38**Required permissions**: ohos.permission.SET_WALLPAPER 39 40**System capability**: SystemCapability.MiscServices.Wallpaper 41 42**System API**: This is a system API. 43 44**Parameters** 45 46| Name| Type| Mandatory| Description| 47| -------- | -------- | -------- | -------- | 48| source | string | Yes| URI of an MP4 file.| 49| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 50| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 51 52**Error codes** 53 54For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 55 56| **ID**| **Error Message** | 57| ------------ | ------------------------------------------- | 58| 201 | permission denied. | 59| 202 | permission verification failed, application which is not a system application uses system API. | 60| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 61 62**Example** 63 64```ts 65import { BusinessError } from '@kit.BasicServicesKit'; 66 67let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4"; 68try { 69 wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 70 if (error) { 71 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 72 return; 73 } 74 console.log(`success to setVideo.`); 75 }); 76} catch (error) { 77 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 78} 79 80``` 81 82## wallpaper.setVideo<sup>10+</sup> 83 84setVideo(source: string, wallpaperType: WallpaperType): Promise<void> 85 86Sets a video resource as the home screen wallpaper or lock screen wallpaper. This API uses a promise to return the result. 87 88**Required permissions**: ohos.permission.SET_WALLPAPER 89 90**System capability**: SystemCapability.MiscServices.Wallpaper 91 92**System API**: This is a system API. 93 94**Parameters** 95 96| Name| Type| Mandatory| Description| 97| -------- | -------- | -------- | -------- | 98| source | string | Yes| URI of an MP4 file.| 99| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 100 101**Error codes** 102 103For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 104 105| **ID**| **Error Message** | 106| ------------ | ------------------------------------------- | 107| 201 | permission denied. | 108| 202 | permission verification failed, application which is not a system application uses system API. | 109| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 110 111**Return value** 112 113| Type| Description| 114| -------- | -------- | 115| Promise<void> | Promise that returns no value.| 116 117**Example** 118 119```ts 120import { BusinessError } from '@kit.BasicServicesKit'; 121 122let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4"; 123try { 124 wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 125 console.log(`success to setVideo.`); 126 }).catch((error: BusinessError) => { 127 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 128 }); 129} catch (error) { 130 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 131} 132``` 133 134## wallpaper.setCustomWallpaper<sup>10+</sup> 135 136setCustomWallpaper(source: string, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 137 138Sets a specific ZIP file as the wallpaper. This API works only when **com.ohos.sceneboard** is set. Applications with the **ohos.permission.GET_WALLPAPER** permission have access to the **/data/wallpaper/** directory. This API uses an asynchronous callback to return the result. 139 140**Required permissions**: ohos.permission.SET_WALLPAPER 141 142**System capability**: SystemCapability.MiscServices.Wallpaper 143 144**System API**: This is a system API. 145 146**Parameters** 147 148| Name| Type| Mandatory| Description| 149| -------- | -------- | -------- | -------- | 150| source | string | Yes| ZIP file to set as the wallpaper.| 151| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 152| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 153 154**Error codes** 155 156For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 157 158| **ID**| **Error Message** | 159| ------------ | ------------------------------------------- | 160| 201 | permission denied. | 161| 202 | permission verification failed, application which is not a system application uses system API. | 162| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 163 164**Example** 165 166```ts 167import { BusinessError } from '@kit.BasicServicesKit'; 168 169let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip"; 170try { 171 wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 172 if (error) { 173 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 174 return; 175 } 176 console.log(`success to setCustomWallpaper.`); 177 }); 178} catch (error) { 179 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 180} 181 182``` 183 184## wallpaper.setCustomWallpaper<sup>10+</sup> 185 186setCustomWallpaper(source: string, wallpaperType: WallpaperType): Promise<void> 187 188Sets a specific ZIP file as the wallpaper. This API works only when **com.ohos.sceneboard** is set. Applications with the **ohos.permission.GET_WALLPAPER** permission have access to the **/data/wallpaper/** directory. This API uses a promise to return the result. 189 190**Required permissions**: ohos.permission.SET_WALLPAPER 191 192**System capability**: SystemCapability.MiscServices.Wallpaper 193 194**System API**: This is a system API. 195 196**Parameters** 197 198| Name| Type| Mandatory| Description| 199| -------- | -------- | -------- | -------- | 200| source | string | Yes| ZIP file to set as the wallpaper.| 201| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 202 203**Return value** 204 205| Type| Description| 206| -------- | -------- | 207| Promise<void> | Promise that returns no value.| 208 209**Error codes** 210 211For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 212 213| **ID**| **Error Message** | 214| ------------ | ------------------------------------------- | 215| 201 | permission denied. | 216| 202 | permission verification failed, application which is not a system application uses system API. | 217| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 218 219**Example** 220 221```ts 222import { BusinessError } from '@kit.BasicServicesKit'; 223 224let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip"; 225try { 226 wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 227 console.log(`success to setCustomWallpaper.`); 228 }).catch((error: BusinessError) => { 229 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 230 }); 231} catch (error) { 232 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 233} 234``` 235 236## wallpaper.on('wallpaperChange')<sup>10+</sup> 237 238on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) => void): void 239 240Subscribes to wallpaper change events. Multi-thread concurrent calls are not supported. 241 242**System capability**: SystemCapability.MiscServices.Wallpaper 243 244**System API**: This is a system API. 245 246**Parameters** 247 248| Name| Type| Mandatory| Description| 249| -------- | -------- | -------- | -------- | 250| type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.| 251| callback | function | Yes| Callback used to return the wallpaper type and wallpaper resource type.<br>- **wallpaperType**: wallpaper type.<br>- **resourceType**: wallpaper resource type.<br>- **uri**: URI of the wallpaper resource.| 252 253**Error codes** 254 255For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 256 257| **ID**| **Error Message** | 258| ------------ | ------------------------------------------- | 259| 202 | permission verification failed, application which is not a system application uses system API. | 260| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 261 262**Example** 263 264```ts 265try { 266 let listener = (wallpaperType: wallpaper.WallpaperType, resourceType: wallpaper.WallpaperResourceType): void => { 267 console.log(`wallpaper color changed.`); 268 }; 269 wallpaper.on('wallpaperChange', listener); 270} catch (error) { 271 console.error(`failed to on because: ${JSON.stringify(error)}`); 272} 273``` 274 275## wallpaper.off('wallpaperChange')<sup>10+</sup> 276 277off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) => void): void 278 279Unsubscribes from wallpaper change events. Multi-thread concurrent calls are not supported. 280 281**System capability**: SystemCapability.MiscServices.Wallpaper 282 283**System API**: This is a system API. 284 285**Parameters** 286 287| Name| Type| Mandatory| Description| 288| -------- | -------- | -------- | -------- | 289| type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.| 290| callback | function | No| Callback used for unsubscription. If this parameter is not set, this API unsubscribes from all callbacks of the specified event type.<br>- **wallpaperType**: wallpaper type.<br>- **resourceType**: wallpaper resource type.<br>- **uri**: URI of the wallpaper resource.| 291 292**Error codes** 293 294For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 295 296| **ID**| **Error Message** | 297| ------------ | ------------------------------------------- | 298| 202 | permission verification failed, application which is not a system application uses system API. | 299| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 300 301**Example** 302 303```ts 304let listener = (wallpaperType: wallpaper.WallpaperType, resourceType: wallpaper.WallpaperResourceType): void => { 305 console.log(`wallpaper color changed.`); 306}; 307try { 308 wallpaper.on('wallpaperChange', listener); 309} catch (error) { 310 console.error(`failed to on because: ${JSON.stringify(error)}`); 311} 312 313try { 314 // Unsubscribe from the listener. 315 wallpaper.off('wallpaperChange', listener); 316} catch (error) { 317 console.error(`failed to off because: ${JSON.stringify(error)}`); 318} 319 320try { 321 // Unsubscribe from all callbacks of the 'wallpaperChange' event type. 322 wallpaper.off('wallpaperChange'); 323} catch (error) { 324 console.error(`failed to off because: ${JSON.stringify(error)}`); 325} 326``` 327 328## wallpaper.getColorsSync<sup>9+</sup> 329 330getColorsSync(wallpaperType: WallpaperType): Array<RgbaColor> 331 332Obtains the main color information of the wallpaper of the specified type. 333 334**System capability**: SystemCapability.MiscServices.Wallpaper 335 336**System API**: This is a system API. 337 338**Parameters** 339 340| Name| Type| Mandatory| Description| 341| -------- | -------- | -------- | -------- | 342| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 343 344**Return value** 345 346| Type| Description| 347| -------- | -------- | 348| Array<[RgbaColor](js-apis-wallpaper.md#rgbacolordeprecated)> | Promise used to return the main color information of the wallpaper.| 349 350**Error codes** 351 352For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 353 354| **ID**| **Error Message** | 355| ------------ | ------------------------------------------- | 356| 202 | permission verification failed, application which is not a system application uses system API. | 357| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 358 359**Example** 360 361```ts 362try { 363 let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); 364 console.log(`success to getColorsSync: ${JSON.stringify(colors)}`); 365} catch (error) { 366 console.error(`failed to getColorsSync because: ${JSON.stringify(error)}`); 367} 368``` 369 370## wallpaper.getMinHeightSync<sup>9+</sup> 371 372getMinHeightSync(): number 373 374Obtains the minimum height of this wallpaper. 375 376**System capability**: SystemCapability.MiscServices.Wallpaper 377 378**System API**: This is a system API. 379 380**Return value** 381 382| Type| Description| 383| -------- | -------- | 384| number | Promise used to return the minimum wallpaper height, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default height should be used instead.| 385 386**Error codes** 387 388For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 389 390| **ID**| **Error Message** | 391| ------------ | ------------------------------------------- | 392| 202 | permission verification failed, application which is not a system application uses system API. | 393 394**Example** 395 396```ts 397let minHeight = wallpaper.getMinHeightSync(); 398``` 399 400## wallpaper.getMinWidthSync<sup>9+</sup> 401 402getMinWidthSync(): number 403 404Obtains the minimum width of this wallpaper. 405 406**System capability**: SystemCapability.MiscServices.Wallpaper 407 408**System API**: This is a system API. 409 410**Return value** 411 412| Type| Description| 413| -------- | -------- | 414| number | Promise used to return the minimum wallpaper width, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default width should be used instead.| 415 416**Error codes** 417 418For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 419 420| **ID**| **Error Message** | 421| ------------ | ------------------------------------------- | 422| 202 | permission verification failed, application which is not a system application uses system API. | 423 424**Example** 425 426```ts 427let minWidth = wallpaper.getMinWidthSync(); 428``` 429 430## wallpaper.restore<sup>9+</sup> 431 432restore(wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 433 434Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result. 435 436**Required permissions**: ohos.permission.SET_WALLPAPER 437 438**System capability**: SystemCapability.MiscServices.Wallpaper 439 440**System API**: This is a system API. 441 442**Parameters** 443 444| Name| Type| Mandatory| Description| 445| -------- | -------- | -------- | -------- | 446| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 447| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| 448 449**Error codes** 450 451For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 452 453| **ID**| **Error Message** | 454| ------------ | ------------------------------------------- | 455| 201 | permission denied. | 456| 202 | permission verification failed, application which is not a system application uses system API. | 457| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 458 459**Example** 460 461```ts 462import { BusinessError } from '@kit.BasicServicesKit'; 463 464wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 465 if (error) { 466 console.error(`failed to restore because: ${JSON.stringify(error)}`); 467 return; 468 } 469 console.log(`success to restore.`); 470}); 471``` 472 473## wallpaper.restore<sup>9+</sup> 474 475restore(wallpaperType: WallpaperType): Promise<void> 476 477Resets the wallpaper of the specified type to the default wallpaper. This API uses a promise to return the result. 478 479**Required permissions**: ohos.permission.SET_WALLPAPER 480 481**System capability**: SystemCapability.MiscServices.Wallpaper 482 483**System API**: This is a system API. 484 485**Parameters** 486 487| Name| Type| Mandatory| Description| 488| -------- | -------- | -------- | -------- | 489| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 490 491**Return value** 492 493| Type| Description| 494| -------- | -------- | 495| Promise<void> | Promise that returns no value.| 496 497**Error codes** 498 499For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 500 501| **ID**| **Error Message** | 502| ------------ | ------------------------------------------- | 503| 201 | permission denied. | 504| 202 | permission verification failed, application which is not a system application uses system API. | 505| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 506 507**Example** 508 509```ts 510import { BusinessError } from '@kit.BasicServicesKit'; 511 512wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 513 console.log(`success to restore.`); 514 }).catch((error: BusinessError) => { 515 console.error(`failed to restore because: ${JSON.stringify(error)}`); 516}); 517``` 518 519## wallpaper.setImage<sup>9+</sup> 520 521setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 522 523Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result. 524 525**Required permissions**: ohos.permission.SET_WALLPAPER 526 527**System capability**: SystemCapability.MiscServices.Wallpaper 528 529**System API**: This is a system API. 530 531**Parameters** 532 533| Name| Type| Mandatory| Description| 534| -------- | -------- | -------- | -------- | 535| source | string \| [image.PixelMap](../apis-image-kit/js-apis-image.md) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 536| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 537| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 538 539**Error codes** 540 541For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 542 543| **ID**| **Error Message** | 544| ------------ | ------------------------------------------- | 545| 201 | permission denied. | 546| 202 | permission verification failed, application which is not a system application uses system API. | 547| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 548 549**Example** 550 551```ts 552import { BusinessError } from '@kit.BasicServicesKit'; 553import { image } from '@kit.ImageKit'; 554 555// The source type is string. 556let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg"; 557wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 558 if (error) { 559 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 560 return; 561 } 562 console.log(`success to setImage.`); 563}); 564 565// The source type is image.PixelMap. 566let imageSource = image.createImageSource("file://" + wallpaperPath); 567let opts: image.DecodingOptions = { 568 desiredSize: { 569 height: 3648, 570 width: 2736 571 } 572}; 573imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => { 574 wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 575 if (error) { 576 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 577 return; 578 } 579 console.log(`success to setImage.`); 580 }); 581}).catch((error: BusinessError) => { 582 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 583}); 584``` 585 586## wallpaper.setImage<sup>9+</sup> 587 588setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> 589 590Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result. 591 592**Required permissions**: ohos.permission.SET_WALLPAPER 593 594**System capability**: SystemCapability.MiscServices.Wallpaper 595 596**System API**: This is a system API. 597 598**Parameters** 599 600| Name| Type| Mandatory| Description| 601| -------- | -------- | -------- | -------- | 602| source | string \| [image.PixelMap](../apis-image-kit/js-apis-image.md) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 603| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 604 605**Return value** 606 607| Type| Description| 608| -------- | -------- | 609| Promise<void> | Promise that returns no value.| 610 611**Error codes** 612 613For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 614 615| **ID**| **Error Message** | 616| ------------ | ------------------------------------------- | 617| 201 | permission denied. | 618| 202 | permission verification failed, application which is not a system application uses system API. | 619| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 620 621**Example** 622 623```ts 624import { BusinessError } from '@kit.BasicServicesKit'; 625import { image } from '@kit.ImageKit'; 626 627// The source type is string. 628let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg"; 629wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 630 console.log(`success to setImage.`); 631}).catch((error: BusinessError) => { 632 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 633}); 634 635// The source type is image.PixelMap. 636let imageSource = image.createImageSource("file://" + wallpaperPath); 637let opts: image.DecodingOptions = { 638 desiredSize: { 639 height: 3648, 640 width: 2736 641 } 642}; 643imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => { 644 wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 645 console.log(`success to setImage.`); 646 }).catch((error: BusinessError) => { 647 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 648 }); 649}).catch((error: BusinessError) => { 650 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 651}); 652``` 653 654## wallpaper.getImage<sup>9+</sup> 655 656getImage(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; 657 658Obtains the pixel map for the wallpaper of the specified type. This API only works for the static wallpaper set using **setImage**. This API uses an asynchronous callback to return the result. 659 660**Required permissions**: ohos.permission.GET_WALLPAPER 661 662**System capability**: SystemCapability.MiscServices.Wallpaper 663 664**System API**: This is a system API. 665 666**Parameters** 667 668| Name| Type| Mandatory| Description| 669| -------- | -------- | -------- | -------- | 670| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 671| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md)> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 672 673**Error codes** 674 675For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 676 677| **ID**| **Error Message** | 678| ------------ | ------------------------------------------- | 679| 201 | permission denied. | 680| 202 | permission verification failed, application which is not a system application uses system API. | 681| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 682 683**Example** 684 685```ts 686import { BusinessError } from '@kit.BasicServicesKit'; 687import { image } from '@kit.ImageKit'; 688 689wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: image.PixelMap) => { 690 if (error) { 691 console.error(`failed to getImage because: ${JSON.stringify(error)}`); 692 return; 693 } 694 console.log(`success to getImage: ${JSON.stringify(data)}`); 695}); 696``` 697 698## wallpaper.getImage<sup>9+</sup> 699 700getImage(wallpaperType: WallpaperType): Promise<image.PixelMap> 701 702Obtains the pixel map for the wallpaper of the specified type. This API only works for the static wallpaper set using **setImage**. This API uses a promise to return the result. 703 704**Required permissions**: ohos.permission.GET_WALLPAPER 705 706**System capability**: SystemCapability.MiscServices.Wallpaper 707 708**System API**: This is a system API. 709 710**Parameters** 711 712| Name| Type| Mandatory| Description| 713| -------- | -------- | -------- | -------- | 714| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 715 716**Return value** 717 718| Type| Description| 719| -------- | -------- | 720| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md)> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 721 722**Error codes** 723 724For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 725 726| **ID**| **Error Message** | 727| ------------ | ------------------------------------------- | 728| 201 | permission denied. | 729| 202 | permission verification failed, application which is not a system application uses system API. | 730| 401 | 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 731 732**Example** 733 734```ts 735import { BusinessError } from '@kit.BasicServicesKit'; 736import { image } from '@kit.ImageKit'; 737 738wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: image.PixelMap) => { 739 console.log(`success to getImage: ${JSON.stringify(data)}`); 740 }).catch((error: BusinessError) => { 741 console.error(`failed to getImage because: ${JSON.stringify(error)}`); 742}); 743``` 744 745## wallpaper.getPixelMap<sup>(deprecated)</sup> 746 747getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; 748 749Obtains the pixel map for the wallpaper of the specified type. 750 751> **NOTE** 752> 753> This API is supported since API version 7 and deprecated since API version 9. 754 755**Required permissions**: ohos.permission.GET_WALLPAPER 756 757**System capability**: SystemCapability.MiscServices.Wallpaper 758 759**System API**: This is a system API. 760 761**Parameters** 762 763| Name| Type| Mandatory| Description| 764| -------- | -------- | -------- | -------- | 765| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 766| callback | AsyncCallback<image.PixelMap> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 767 768**Example** 769 770```ts 771import { BusinessError } from '@kit.BasicServicesKit'; 772import { image } from '@kit.ImageKit'; 773 774wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: image.PixelMap) => { 775 if (error) { 776 console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`); 777 return; 778 } 779 console.log(`success to getPixelMap : ${JSON.stringify(data)}`); 780 }); 781``` 782 783## wallpaper.getPixelMap<sup>(deprecated)</sup> 784 785getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap> 786 787Obtains the pixel map for the wallpaper of the specified type. 788 789> **NOTE** 790> 791> This API is supported since API version 7 and deprecated since API version 9. 792 793**Required permissions**: ohos.permission.GET_WALLPAPER 794 795**System capability**: SystemCapability.MiscServices.Wallpaper 796 797**System API**: This is a system API. 798 799**Parameters** 800 801| Name| Type| Mandatory| Description| 802| -------- | -------- | -------- | -------- | 803| wallpaperType | [WallpaperType](js-apis-wallpaper.md#wallpapertype7) | Yes| Wallpaper type.| 804 805**Return value** 806 807| Type| Description| 808| -------- | -------- | 809| Promise<image.PixelMap> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 810 811**Example** 812 813```ts 814import { BusinessError } from '@kit.BasicServicesKit'; 815import { image } from '@kit.ImageKit'; 816 817wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: image.PixelMap) => { 818 console.log(`success to getPixelMap : ${JSON.stringify(data)}`); 819 }).catch((error: BusinessError) => { 820 console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`); 821}); 822``` 823