1/* 2 * Copyright (C) 2024 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 16/** 17 * @file 18 * @kit ImageKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22import type colorSpaceManager from './@ohos.graphics.colorSpaceManager'; 23import type image from './@ohos.multimedia.image'; 24import type resourceManager from './@ohos.resourceManager'; 25import type rpc from './@ohos.rpc'; 26import lang from '../arkts/@arkts.lang'; 27import collections from '../arkts/@arkts.collections'; 28 /** 29 * This module provides the capability of image codec and access 30 * @namespace sendableImage 31 * @syscap SystemCapability.Multimedia.Image.Core 32 * @crossplatform 33 * @atomicservice 34 * @since 12 35 */ 36declare namespace sendableImage { 37 38 /** 39 * Describes the size of an image. 40 * 41 * @typedef Size 42 * @syscap SystemCapability.Multimedia.Image.Core 43 * @crossplatform 44 * @form 45 * @atomicservice 46 * @since 12 47 */ 48 interface Size extends lang.ISendable { 49 /** 50 * Height 51 * 52 * @type { number } 53 * @syscap SystemCapability.Multimedia.Image.Core 54 * @crossplatform 55 * @form 56 * @atomicservice 57 * @since 12 58 */ 59 height: number; 60 61 /** 62 * Width 63 * 64 * @type { number } 65 * @syscap SystemCapability.Multimedia.Image.Core 66 * @crossplatform 67 * @form 68 * @atomicservice 69 * @since 12 70 */ 71 width: number; 72} 73 74/** 75 * Describes region information. 76 * 77 * @typedef Region 78 * @syscap SystemCapability.Multimedia.Image.Core 79 * @crossplatform 80 * @form 81 * @atomicservice 82 * @since 12 83 */ 84interface Region extends lang.ISendable { 85 /** 86 * Image size. 87 * 88 * @type { Size } 89 * @syscap SystemCapability.Multimedia.Image.Core 90 * @crossplatform 91 * @form 92 * @atomicservice 93 * @since 12 94 */ 95 size: Size; 96 97 /** 98 * x-coordinate at the upper left corner of the image. 99 * 100 * @type { number } 101 * @syscap SystemCapability.Multimedia.Image.Core 102 * @crossplatform 103 * @form 104 * @atomicservice 105 * @since 12 106 */ 107 x: number; 108 109 /** 110 * y-coordinate at the upper left corner of the image. 111 * 112 * @type { number } 113 * @syscap SystemCapability.Multimedia.Image.Core 114 * @crossplatform 115 * @form 116 * @atomicservice 117 * @since 12 118 */ 119 y: number; 120} 121 122 /** 123 * Creates an ImageSource instance based on the URI. 124 * 125 * @param { string } uri Image source URI. 126 * @returns { ImageSource } returns the ImageSource instance if the operation is successful; returns null otherwise. 127 * @syscap SystemCapability.Multimedia.Image.ImageSource 128 * @crossplatform 129 * @atomicservice 130 * @since 12 131 */ 132 function createImageSource(uri: string): ImageSource; 133 134 /** 135 * Creates an ImageSource instance based on the file descriptor. 136 * 137 * @param { number } fd ID of a file descriptor. 138 * @returns { ImageSource } Returns the ImageSource instance if the operation is successful; returns null otherwise. 139 * @syscap SystemCapability.Multimedia.Image.ImageSource 140 * @crossplatform 141 * @atomicservice 142 * @since 12 143 */ 144 function createImageSource(fd: number): ImageSource; 145 146 /** 147 * Creates an ImageSource instance based on the buffer. 148 * 149 * @param { ArrayBuffer } buf The buffer of the image. 150 * @returns { ImageSource } Returns the ImageSource instance if the operation is successful; returns null otherwise. 151 * @syscap SystemCapability.Multimedia.Image.ImageSource 152 * @crossplatform 153 * @form 154 * @atomicservice 155 * @since 12 156 */ 157 function createImageSource(buf: ArrayBuffer): ImageSource; 158 159 /** 160 * Creates an ImageReceiver instance. 161 * 162 * @param { Size } size - The default {@link Size} in pixels of the Images that this receiver will produce. 163 * @param { ImageFormat } format - The format of the Image that this receiver will produce. This must be one of the 164 * {@link ImageFormat} constants. 165 * @param { number } capacity - The maximum number of images the user will want to access simultaneously. 166 * @returns { ImageReceiver } Returns the ImageReceiver instance if the operation is successful; returns null otherwise. 167 * @throws { BusinessError } 401 - The parameter check failed. 168 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 169 * @since 12 170 */ 171 function createImageReceiver(size: image.Size, format: image.ImageFormat, capacity: number): ImageReceiver; 172 173 type ISendable = lang.ISendable; 174 175 /** 176 * Create PixelMap by data buffer. 177 * 178 * @param { ArrayBuffer } colors The image color buffer. 179 * @param { InitializationOptions } options Initialization options for PixelMap. 180 * @returns { Promise<PixelMap> } A Promise instance used to return the PixelMap object. 181 * @syscap SystemCapability.Multimedia.Image.Core 182 * @crossplatform 183 * @since 12 184 */ 185 function createPixelMap(colors: ArrayBuffer, options: image.InitializationOptions): Promise<PixelMap>; 186 187 /** 188 * Create PixelMap by data buffer. 189 * 190 * @param { ArrayBuffer } colors The image color buffer. 191 * @param { InitializationOptions } options Initialization options for PixelMap. 192 * @returns { PixelMap } Returns the instance if the operation is successful;Otherwise, return undefined. 193 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 194 * 2.Incorrect parameter types. 3.Parameter verification failed. 195 * @syscap SystemCapability.Multimedia.Image.Core 196 * @crossplatform 197 * @since 12 198 */ 199 function createPixelMapSync(colors: ArrayBuffer, options: image.InitializationOptions): PixelMap; 200 201 /** 202 * Creates a PixelMap object based on MessageSequence parameter. 203 * 204 * @param { rpc.MessageSequence } sequence - rpc.MessageSequence parameter. 205 * @returns { PixelMap } Returns the instance if the operation is successful. 206 * Otherwise, an exception will be thrown. 207 * @throws { BusinessError } 62980096 - Operation failed. 208 * @throws { BusinessError } 62980097 - IPC error. 209 * @throws { BusinessError } 62980115 - Invalid input parameter. 210 * @throws { BusinessError } 62980105 - Failed to get the data. 211 * @throws { BusinessError } 62980177 - Abnormal API environment. 212 * @throws { BusinessError } 62980178 - Failed to create the PixelMap. 213 * @throws { BusinessError } 62980179 - Abnormal buffer size. 214 * @throws { BusinessError } 62980180 - FD mapping failed. 215 * @throws { BusinessError } 62980246 - Failed to read the PixelMap. 216 * @syscap SystemCapability.Multimedia.Image.Core 217 * @since 12 218 */ 219 function createPixelMapFromParcel(sequence: rpc.MessageSequence): PixelMap; 220 221 /** 222 * Creates a PixelMap object from surface id. 223 * 224 * @param { string } surfaceId - surface id. 225 * @param { Region } region - The region to surface. 226 * @returns { Promise<PixelMap> } Returns the instance if the operation is successful. 227 * Otherwise, an exception will be thrown. 228 * @throws { BusinessError } 62980115 - If the image parameter invalid. 229 * @throws { BusinessError } 62980105 - Failed to get the data. 230 * @throws { BusinessError } 62980178 - Failed to create the PixelMap. 231 * @syscap SystemCapability.Multimedia.Image.Core 232 * @since 12 233 */ 234 function createPixelMapFromSurface(surfaceId: string, region: image.Region): Promise<PixelMap>; 235 236 /** 237 * Creates a sendable image PixelMap from image PixelMap. 238 * 239 * @param { image.PixelMap } pixelmap - the src pixelmap. 240 * @returns { PixelMap } Returns the instance if the operation is successful. 241 * Otherwise, an exception will be thrown. 242 * @throws { BusinessError } 401 - If the image parameter invalid. Possible causes: 243 * 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. 244 * @throws { BusinessError } 62980104 - Failed to initialize the internal object. 245 * @syscap SystemCapability.Multimedia.Image.Core 246 * @since 12 247 */ 248 function convertFromPixelMap(pixelmap: image.PixelMap): PixelMap; 249 250 /** 251 * Creates a image PixelMap from sendable image PixelMap. 252 * 253 * @param { PixelMap } pixelmap - the src pixelmap. 254 * @returns { image.PixelMap } Returns the instance if the operation is successful. 255 * Otherwise, an exception will be thrown. 256 * @throws { BusinessError } 401 - If the image parameter invalid. Possible causes: 257 * 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. 258 * @throws { BusinessError } 62980104 - Failed to initialize the internal object. 259 * @syscap SystemCapability.Multimedia.Image.Core 260 * @since 12 261 */ 262 function convertToPixelMap(pixelmap: PixelMap): image.PixelMap; 263 264 /** 265 * Sendable PixelMap instance. 266 * 267 * @typedef PixelMap 268 * @syscap SystemCapability.Multimedia.Image.Core 269 * @crossplatform 270 * @atomicservice 271 * @since 12 272 */ 273 interface PixelMap extends ISendable { 274 /** 275 * Whether the image pixelmap can be edited. 276 * 277 * @type { boolean } 278 * @syscap SystemCapability.Multimedia.Image.Core 279 * @crossplatform 280 * @atomicservice 281 * @since 12 282 */ 283 readonly isEditable: boolean; 284 285 /** 286 * Reads image pixelmap data and writes the data to an ArrayBuffer. This method uses 287 * a promise to return the result. 288 * 289 * @param { ArrayBuffer } dst A buffer to which the image pixelmap data will be written. 290 * @returns { Promise<void> } A Promise instance used to return the operation result. 291 * If the operation fails, an error message is returned. 292 * @syscap SystemCapability.Multimedia.Image.Core 293 * @crossplatform 294 * @atomicservice 295 * @since 12 296 */ 297 readPixelsToBuffer(dst: ArrayBuffer): Promise<void>; 298 299 /** 300 * Reads image pixelmap data and writes the data to an ArrayBuffer. 301 * 302 * @param { ArrayBuffer } dst A buffer to which the image pixelmap data will be written. 303 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 304 * 2.Incorrect parameter types. 3.Parameter verification failed. 305 * @throws { BusinessError } 501 - Resource Unavailable. 306 * @syscap SystemCapability.Multimedia.Image.Core 307 * @crossplatform 308 * @atomicservice 309 * @since 12 310 */ 311 readPixelsToBufferSync(dst: ArrayBuffer): void; 312 313 /** 314 * Reads image pixelmap data in an area. This method uses a promise to return the data read. 315 * 316 * @param { PositionArea } area Area from which the image pixelmap data will be read. 317 * @returns { Promise<void> } A Promise instance used to return the operation result. 318 * If the operation fails, an error message is returned. 319 * @syscap SystemCapability.Multimedia.Image.Core 320 * @crossplatform 321 * @atomicservice 322 * @since 12 323 */ 324 readPixels(area: image.PositionArea): Promise<void>; 325 326 /** 327 * Reads image pixelmap data in an area. 328 * 329 * @param { PositionArea } area Area from which the image pixelmap data will be read. 330 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 331 * 2.Incorrect parameter types. 3.Parameter verification failed. 332 * @throws { BusinessError } 501 - Resource Unavailable. 333 * @syscap SystemCapability.Multimedia.Image.Core 334 * @crossplatform 335 * @atomicservice 336 * @since 12 337 */ 338 readPixelsSync(area: image.PositionArea): void; 339 340 /** 341 * Writes image pixelmap data to the specified area. This method uses a promise to return 342 * the operation result. 343 * 344 * @param { PositionArea } area Area to which the image pixelmap data will be written. 345 * @returns { Promise<void> } A Promise instance used to return the operation result. 346 * If the operation fails, an error message is returned. 347 * @syscap SystemCapability.Multimedia.Image.Core 348 * @crossplatform 349 * @atomicservice 350 * @since 12 351 */ 352 writePixels(area: image.PositionArea): Promise<void>; 353 354 /** 355 * Writes image pixelmap data to the specified area. 356 * 357 * @param { PositionArea } area Area to which the image pixelmap data will be written. 358 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 359 * 2.Incorrect parameter types. 3.Parameter verification failed. 360 * @throws { BusinessError } 501 - Resource Unavailable. 361 * @syscap SystemCapability.Multimedia.Image.Core 362 * @crossplatform 363 * @atomicservice 364 * @since 12 365 */ 366 writePixelsSync(area: image.PositionArea): void; 367 368 /** 369 * Reads image data in an ArrayBuffer and writes the data to a PixelMap object. This method 370 * uses a promise to return the result. 371 * 372 * @param { ArrayBuffer } src A buffer from which the image data will be read. 373 * @returns { Promise<void> } A Promise instance used to return the operation result. 374 * If the operation fails, an error message is returned. 375 * @syscap SystemCapability.Multimedia.Image.Core 376 * @crossplatform 377 * @atomicservice 378 * @since 12 379 */ 380 writeBufferToPixels(src: ArrayBuffer): Promise<void>; 381 382 /** 383 * Reads image data in an ArrayBuffer and writes the data to a PixelMap object. 384 * 385 * @param { ArrayBuffer } src A buffer from which the image data will be read. 386 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 387 * 2.Incorrect parameter types. 3.Parameter verification failed. 388 * @throws { BusinessError } 501 - Resource Unavailable. 389 * @syscap SystemCapability.Multimedia.Image.Core 390 * @crossplatform 391 * @atomicservice 392 * @since 12 393 */ 394 writeBufferToPixelsSync(src: ArrayBuffer): void; 395 396 /** 397 * Obtains pixelmap information about this image. This method uses a promise to return the information. 398 * 399 * @returns { Promise<ImageInfo> } A Promise instance used to return the image pixelmap information. 400 * If the operation fails, an error message is returned. 401 * @syscap SystemCapability.Multimedia.Image.Core 402 * @crossplatform 403 * @atomicservice 404 * @since 12 405 */ 406 getImageInfo(): Promise<image.ImageInfo>; 407 408 /** 409 * Get image information from image source. 410 * 411 * @returns { ImageInfo } the image information. 412 * @throws { BusinessError } 501 - Resource Unavailable. 413 * @syscap SystemCapability.Multimedia.Image.ImageSource 414 * @crossplatform 415 * @atomicservice 416 * @since 12 417 */ 418 getImageInfoSync(): image.ImageInfo; 419 420 /** 421 * Obtains the number of bytes in each line of the image pixelmap. 422 * 423 * @returns { number } Number of bytes in each line. 424 * @syscap SystemCapability.Multimedia.Image.Core 425 * @crossplatform 426 * @atomicservice 427 * @since 12 428 */ 429 getBytesNumberPerRow(): number; 430 431 /** 432 * Obtains the total number of bytes of the image pixelmap. 433 * 434 * @returns { number } Total number of bytes. 435 * @syscap SystemCapability.Multimedia.Image.Core 436 * @crossplatform 437 * @atomicservice 438 * @since 12 439 */ 440 getPixelBytesNumber(): number; 441 442 /** 443 * Obtains the density of the image pixelmap. 444 * 445 * @returns { number } The number of density. 446 * @syscap SystemCapability.Multimedia.Image.Core 447 * @crossplatform 448 * @atomicservice 449 * @since 12 450 */ 451 getDensity(): number; 452 453 /** 454 * Set the transparent rate of pixelmap. This method uses a promise to return the result. 455 * 456 * @param { number } rate The value of transparent rate. 457 * @returns { Promise<void> } A Promise instance used to return the operation result. 458 * If the operation fails, an error message is returned. 459 * @syscap SystemCapability.Multimedia.Image.Core 460 * @crossplatform 461 * @atomicservice 462 * @since 12 463 */ 464 opacity(rate: number): Promise<void>; 465 466 /** 467 * Set the transparent rate of pixelmap. 468 * 469 * @param { number } rate The value of transparent rate. 470 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 471 * 2.Incorrect parameter types. 3.Parameter verification failed. 472 * @throws { BusinessError } 501 - Resource Unavailable. 473 * @syscap SystemCapability.Multimedia.Image.Core 474 * @crossplatform 475 * @atomicservice 476 * @since 12 477 */ 478 opacitySync(rate: number): void; 479 480 /** 481 * Obtains new pixelmap with alpha information. This method uses a promise to return the information. 482 * 483 * @returns { Promise<PixelMap> } A Promise instance used to return the new image pixelmap. 484 * If the operation fails, an error message is returned. 485 * @syscap SystemCapability.Multimedia.Image.Core 486 * @crossplatform 487 * @atomicservice 488 * @since 12 489 */ 490 createAlphaPixelmap(): Promise<PixelMap>; 491 492 /** 493 * Obtains new pixelmap with alpha information. 494 * 495 * @returns { PixelMap } return the new image pixelmap. 496 * If the operation fails, an error message is returned. 497 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Parameter verification failed. 498 * @throws { BusinessError } 501 - Resource Unavailable. 499 * @syscap SystemCapability.Multimedia.Image.Core 500 * @crossplatform 501 * @atomicservice 502 * @since 12 503 */ 504 createAlphaPixelmapSync(): PixelMap; 505 506 /** 507 * Image zoom in width and height. This method uses a promise to return the result. 508 * 509 * @param { number } x The zoom value of width. 510 * @param { number } y The zoom value of height. 511 * @returns { Promise<void> } A Promise instance used to return the operation result. 512 * If the operation fails, an error message is returned. 513 * @syscap SystemCapability.Multimedia.Image.Core 514 * @crossplatform 515 * @atomicservice 516 * @since 12 517 */ 518 scale(x: number, y: number): Promise<void>; 519 520 /** 521 * Image zoom in width and height. 522 * 523 * @param { number } x The zoom value of width. 524 * @param { number } y The zoom value of height. 525 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 526 * 2.Incorrect parameter types. 3.Parameter verification failed. 527 * @throws { BusinessError } 501 - Resource Unavailable. 528 * @syscap SystemCapability.Multimedia.Image.Core 529 * @crossplatform 530 * @atomicservice 531 * @since 12 532 */ 533 scaleSync(x: number, y: number): void; 534 535 /** 536 * Image position transformation. This method uses a promise to return the result. 537 * 538 * @param { number } x The position value of width. 539 * @param { number } y The position value of height. 540 * @returns { Promise<void> } A Promise instance used to return the operation result. 541 * If the operation fails, an error message is returned. 542 * @syscap SystemCapability.Multimedia.Image.Core 543 * @crossplatform 544 * @atomicservice 545 * @since 12 546 */ 547 translate(x: number, y: number): Promise<void>; 548 549 /** 550 * Image position transformation. 551 * 552 * @param { number } x The position value of width. 553 * @param { number } y The position value of height. 554 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 555 * 2.Incorrect parameter types. 3.Parameter verification failed. 556 * @throws { BusinessError } 501 - Resource Unavailable. 557 * @syscap SystemCapability.Multimedia.Image.Core 558 * @crossplatform 559 * @atomicservice 560 * @since 12 561 */ 562 translateSync(x: number, y: number): void; 563 564 /** 565 * Image rotation. This method uses a promise to return the result. 566 * 567 * @param { number } angle The rotation angle. 568 * @returns { Promise<void> } A Promise instance used to return the operation result. 569 * If the operation fails, an error message is returned. 570 * @syscap SystemCapability.Multimedia.Image.Core 571 * @crossplatform 572 * @atomicservice 573 * @since 12 574 */ 575 rotate(angle: number): Promise<void>; 576 577 /** 578 * Image rotation. 579 * 580 * @param { number } angle The rotation angle. 581 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 582 * 2.Incorrect parameter types. 3.Parameter verification failed. 583 * @throws { BusinessError } 501 - Resource Unavailable. 584 * @syscap SystemCapability.Multimedia.Image.Core 585 * @crossplatform 586 * @atomicservice 587 * @since 12 588 */ 589 rotateSync(angle: number): void; 590 591 /** 592 * Image flipping. This method uses a promise to return the result. 593 * 594 * @param { boolean } horizontal Is flip in horizontal. 595 * @param { boolean } vertical Is flip in vertical. 596 * @returns { Promise<void> } A Promise instance used to return the operation result. 597 * If the operation fails, an error message is returned. 598 * @syscap SystemCapability.Multimedia.Image.Core 599 * @crossplatform 600 * @atomicservice 601 * @since 12 602 */ 603 flip(horizontal: boolean, vertical: boolean): Promise<void>; 604 605 /** 606 * Image flipping. 607 * 608 * @param { boolean } horizontal Is flip in horizontal. 609 * @param { boolean } vertical Is flip in vertical. 610 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 611 * 2.Incorrect parameter types. 3.Parameter verification failed. 612 * @throws { BusinessError } 501 - Resource Unavailable. 613 * @syscap SystemCapability.Multimedia.Image.Core 614 * @crossplatform 615 * @atomicservice 616 * @since 12 617 */ 618 flipSync(horizontal: boolean, vertical: boolean): void; 619 620 /** 621 * Crop the image. This method uses a promise to return the result. 622 * 623 * @param { Region } region The region to crop. 624 * @returns { Promise<void> } A Promise instance used to return the operation result. 625 * If the operation fails, an error message is returned. 626 * @syscap SystemCapability.Multimedia.Image.Core 627 * @crossplatform 628 * @atomicservice 629 * @since 12 630 */ 631 crop(region: image.Region): Promise<void>; 632 633 /** 634 * Crop the image. 635 * 636 * @param { Region } region The region to crop. 637 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 638 * 2.Incorrect parameter types. 3.Parameter verification failed. 639 * @throws { BusinessError } 501 - Resource Unavailable. 640 * @syscap SystemCapability.Multimedia.Image.Core 641 * @crossplatform 642 * @atomicservice 643 * @since 12 644 */ 645 cropSync(region: image.Region): void; 646 647 /** 648 * Get color space of pixelmap. 649 * 650 * @returns { colorSpaceManager.ColorSpaceManager } If the operation fails, an error message is returned. 651 * @throws { BusinessError } 62980101 - If the image data abnormal. 652 * @throws { BusinessError } 62980103 - If the image data unsupport. 653 * @throws { BusinessError } 62980115 - If the image parameter invalid. 654 * @syscap SystemCapability.Multimedia.Image.Core 655 * @crossplatform 656 * @since 12 657 */ 658 getColorSpace(): colorSpaceManager.ColorSpaceManager; 659 660 /** 661 * Set color space of pixelmap. 662 * 663 * This method is only used to set the colorspace property of PixelMap, 664 * while all pixel data remains the same after calling this method. 665 * If you want to change colorspace for all pixels, use method 666 * {@Link #applyColorSpace(colorSpaceManager.ColorSpaceManager)}. 667 * 668 * @param { colorSpaceManager.ColorSpaceManager } colorSpace The color space for pixelmap. 669 * @throws { BusinessError } 62980111 - If the operation invalid. 670 * @throws { BusinessError } 62980115 - If the image parameter invalid. 671 * @syscap SystemCapability.Multimedia.Image.Core 672 * @crossplatform 673 * @since 12 674 */ 675 setColorSpace(colorSpace: colorSpaceManager.ColorSpaceManager): void; 676 677 /** 678 * Is it stride Alignment 679 * 680 * @type { boolean } 681 * @readonly 682 * @syscap SystemCapability.Multimedia.Image.Core 683 * @since 12 684 */ 685 readonly isStrideAlignment: boolean; 686 687 /** 688 * Apply color space of pixelmap, the pixels will be changed by input color space. 689 * This method uses a promise to return the result. 690 * 691 * This method is used to change color space of PixelMap. 692 * Pixel data will be changed by calling this method. 693 * If you want to set the colorspace property of PixelMap only, 694 * use method {@Link #setColorSpace(colorSpaceManager.ColorSpaceManager)}. 695 * 696 * @param { colorSpaceManager.ColorSpaceManager } targetColorSpace - The color space for pixelmap. 697 * @returns { Promise<void> } A Promise instance used to return the operation result. 698 * If the operation fails, an error message is returned. 699 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 700 * 2.Incorrect parameter types. 3.Parameter verification failed. 701 * @throws { BusinessError } 62980104 - Failed to initialize the internal object. 702 * @throws { BusinessError } 62980108 - Failed to convert the color space. 703 * @throws { BusinessError } 62980115 - Invalid image parameter. 704 * @syscap SystemCapability.Multimedia.Image.Core 705 * @crossplatform 706 * @since 12 707 */ 708 applyColorSpace(targetColorSpace: colorSpaceManager.ColorSpaceManager): Promise<void>; 709 710 /** 711 * Releases this PixelMap object. This method uses a promise to return the result. 712 * 713 * @returns { Promise<void> } A Promise instance used to return the instance release result. 714 * If the operation fails, an error message is returned. 715 * @syscap SystemCapability.Multimedia.Image.Core 716 * @crossplatform 717 * @atomicservice 718 * @since 12 719 */ 720 release(): Promise<void>; 721 722 /** 723 * Marshalling PixelMap and write into MessageSequence. 724 * 725 * @param { rpc.MessageSequence } sequence rpc.MessageSequence parameter. 726 * @throws { BusinessError } 62980115 - Invalid image parameter. 727 * @throws { BusinessError } 62980097 - IPC error. 728 * @syscap SystemCapability.Multimedia.Image.Core 729 * @since 12 730 */ 731 marshalling(sequence: rpc.MessageSequence): void; 732 733 /** 734 * Creates a PixelMap object based on MessageSequence parameter. 735 * 736 * @param { rpc.MessageSequence } sequence rpc.MessageSequence parameter. 737 * @returns { Promise<PixelMap> } A Promise instance used to return the PixelMap object. 738 * @throws { BusinessError } 62980115 - Invalid image parameter. 739 * @throws { BusinessError } 62980097 - IPC error. 740 * @throws { BusinessError } 62980096 - The operation failed. 741 * @syscap SystemCapability.Multimedia.Image.Core 742 * @since 12 743 */ 744 unmarshalling(sequence: rpc.MessageSequence): Promise<PixelMap>; 745 } 746 747 /** 748 * ImageSource instance. 749 * 750 * @typedef ImageSource 751 * @syscap SystemCapability.Multimedia.Image.ImageSource 752 * @crossplatform 753 * @form 754 * @atomicservice 755 * @since 12 756 */ 757 interface ImageSource { 758 /** 759 * Creates a PixelMap object based on image decoding parameters. This method uses a promise to 760 * return the object. 761 * 762 * @param { DecodingOptions } options Image decoding parameters. 763 * @returns { Promise<PixelMap> } A Promise instance used to return the PixelMap object. 764 * @syscap SystemCapability.Multimedia.Image.ImageSource 765 * @crossplatform 766 * @form 767 * @atomicservice 768 * @since 12 769 */ 770 createPixelMap(options?: image.DecodingOptions): Promise<PixelMap>; 771 772 /** 773 * Releases an ImageSource instance and uses a promise to return the result. 774 * 775 * @returns { Promise<void> } A Promise instance used to return the operation result. 776 * @syscap SystemCapability.Multimedia.Image.ImageSource 777 * @crossplatform 778 * @since 12 779 */ 780 release(): Promise<void>; 781 } 782 783 /** 784 * Provides basic image operations, including obtaining image information, and reading and writing image data. 785 * 786 * @typedef Image 787 * @syscap SystemCapability.Multimedia.Image.Core 788 * @since 12 789 */ 790 interface Image extends lang.ISendable { 791 /** 792 * Sets or gets the image area to crop, default is size. 793 * 794 * @type { Region } 795 * @syscap SystemCapability.Multimedia.Image.Core 796 * @since 12 797 */ 798 clipRect: Region; 799 800 /** 801 * Image size. 802 * 803 * @type { Size } 804 * @syscap SystemCapability.Multimedia.Image.Core 805 * @since 12 806 */ 807 readonly size: Size; 808 809 /** 810 * Image format. 811 * 812 * @type { number } 813 * @syscap SystemCapability.Multimedia.Image.Core 814 * @since 12 815 */ 816 readonly format: number; 817 818 /** 819 * Image timestamp. 820 * 821 * @type { number } 822 * @syscap SystemCapability.Multimedia.Image.Core 823 * @since 12 824 */ 825 readonly timestamp: number; 826 827 /** 828 * Get component buffer from image and uses a promise to return the result. 829 * 830 * @param { ComponentType } componentType The component type of image. 831 * @returns { Promise<Component> } A Promise instance used to return the component buffer. 832 * @syscap SystemCapability.Multimedia.Image.Core 833 * @since 12 834 */ 835 getComponent(componentType: image.ComponentType): Promise<image.Component>; 836 837 /** 838 * Release current image to receive another and uses a promise to return the result. 839 * 840 * @returns { Promise<void> } A Promise instance used to return the operation result. 841 * @syscap SystemCapability.Multimedia.Image.Core 842 * @since 12 843 */ 844 release(): Promise<void>; 845 } 846 847 /** 848 * Image receiver object. 849 * 850 * @typedef ImageReceiver 851 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 852 * @since 12 853 */ 854 interface ImageReceiver { 855 /** 856 * Image size. 857 * 858 * @type { Size } 859 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 860 * @since 12 861 */ 862 readonly size: image.Size; 863 864 /** 865 * Image capacity. 866 * 867 * @type { number } 868 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 869 * @since 12 870 */ 871 readonly capacity: number; 872 873 /** 874 * Image format. 875 * 876 * @type { ImageFormat } 877 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 878 * @since 12 879 */ 880 readonly format: image.ImageFormat; 881 882 /** 883 * Get an id which indicates a surface and can be used to set to Camera or other component can receive a surface 884 * and uses a promise to return the result. 885 * 886 * @returns { Promise<string> } A Promise instance used to return the surface id. 887 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 888 * @since 12 889 */ 890 getReceivingSurfaceId(): Promise<string>; 891 892 /** 893 * Get lasted image from receiver and uses a promise to return the result. 894 * 895 * @returns { Promise<Image> } A Promise instance used to return the latest image. 896 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 897 * @since 12 898 */ 899 readLatestImage(): Promise<Image>; 900 901 /** 902 * Get next image from receiver and uses a promise to return the result. 903 * 904 * @returns { Promise<Image> } A Promise instance used to return the next image. 905 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 906 * @since 12 907 */ 908 readNextImage(): Promise<Image>; 909 910 /** 911 * Subscribe callback when receiving an image 912 * 913 * @param { 'imageArrival' } type Callback used to return the next image. 914 * @param { AsyncCallback<void> } callback Callback used to return image. 915 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 916 * @since 12 917 */ 918 on(type: 'imageArrival', callback: AsyncCallback<void>): void; 919 920 /** 921 * Release image receiver instance and uses a promise to return the result. 922 * 923 * @returns { Promise<void> } A Promise instance used to return the operation result. 924 * @syscap SystemCapability.Multimedia.Image.ImageReceiver 925 * @since 12 926 */ 927 release(): Promise<void>; 928 } 929 930} 931 932export default sendableImage;