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