19 Star 17 Fork 450

OpenHarmony / multimedia_image_framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Image组件

简介

image_framework仓库提供了一系列易用的接口用于存放image的源码信息,提供创建图片源和位图管理能力,支持运行标准系统的设备使用。

图1 Image组件架构图

支持能力列举如下:

  • 创建、释放位图。
  • 读写像素。
  • 获取位图信息。
  • 创建、释放图片源。
  • 获取图片源信息。
  • 创建、释放packer实例。

目录

仓目录结构如下:

/foundation/multimedia/image_framework  
├── frameworks                                  # 框架代码
│   ├── innerkitsimpl                           # 内部接口实现
│   │   └──image                                # Native 实现
│   └── kitsimpl                                # 外部接口实现
│       └──image                                # 外部  NAPI 实现
├── interfaces                                  # 接口代码
│   ├── innerkits                               # 内部 Native 接口
│   └── kits                                    # 外部 JS 接口
├── LICENSE                                     # 证书文件
├── ohos.build                                  # 编译文件
├── sa_profile                                  # 服务配置文件
└── services                                    # 服务实现

使用说明

1.读像素到数组

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何将像素读到缓冲区。

通过调用readPixelsToBuffer读pixels到buffer。

readPixelsToBuffer(dst: ArrayBuffer): Promise<void>;
readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback<void>): void;

示例:

pixelmap.readPixelsToBuffer(readBuffer).then(() => {})

2.读pixels

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何按照区域读像素。

通过调用readPixels读pixels。

readPixels(area: PositionArea): Promise<void>;
readPixels(area: PositionArea, callback: AsyncCallback<void>): void;

示例:

pixelmap.readPixels(area).then(() => {})

3.写pixels

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何写像素。

通过调用writepixels写到指定区域。

writePixels(area: PositionArea): Promise<void>;
writePixels(area: PositionArea, callback: AsyncCallback<void>): void;

示例:

pixelmap.writePixels(area, () => {})

4.writeBufferToPixels

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何将数据写进pixels。

通过调用writeBufferToPixels写到pixel。

writeBufferToPixels(src: ArrayBuffer): Promise<void>;
writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback<void>): void;

示例:

pixelmap.writeBufferToPixels(writeColor, () => {})

5.getImageInfo

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何获取图片信息。

通过调用getImageInfo获取图片基本信息。

1.使用create通过属性创建pixelmap。

image.createPixelMap(color, opts, pixelmap =>{})

2.使用getImageInfo获取图片基本信息。

pixelmap.getImageInfo( imageInfo => {})

6.getBytesNumberPerRow

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何获取每行字节数。

通过调用getBytesNumberPerRow获取字节数。

getBytesNumberPerRow(): Promise<number>;
getBytesNumberPerRow(callback: AsyncCallback<number>): void;

示例:

pixelmap.getBytesNumberPerRow((num) => {})

7.getPixelBytesNumber

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何获取buffer。

通过调用getPixelBytesNumber获取buffer数。

getPixelBytesNumber(): Promise<number>;
getPixelBytesNumber(callback: AsyncCallback<number>): void;

示例:

pixelmap.getPixelBytesNumber().then((num) => {
          console.info('TC_026 num is ' + num)
          expect(num == expectNum).assertTrue()
          done()
        })

8.getDensity

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何获取图片像素密度。

通过调用getDensity获取图片像素密度。

getDensity():number;

示例:

let getDensity = pixelmap.getDensity();

9.opacity

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何设置图片透明比率。

通过调用opacity设置图片透明比率。

opacity(rate: number, callback: AsyncCallback<void>): void;
opacity(rate: number): Promise<void>;

示例:

async function () {
	await pixelMap.opacity(0.5);
}

10.createAlphaPixelmap

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何生成一个仅包含Alpha通道信息的pixelmap。

通过调用createAlphaPixelmap生成一个仅包含Alpha通道信息的pixelmap,可用于阴影效果。

createAlphaPixelmap(): Promise<PixelMap>;
createAlphaPixelmap(callback: AsyncCallback<PixelMap>): void;

示例:

pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => {})

11.scale

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何根据输入的宽高对图片进行缩放。

通过调用scale对图片进行缩放。

scale(x: number, y: number, callback: AsyncCallback<void>): void;
scale(x: number, y: number): Promise<void>;

示例:

await pixelMap.scale(2.0, 1.0);

12.translate

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何根据输入的坐标对图片进行位置变换。

通过调用translate对图片进行位置变换。

translate(x: number, y: number, callback: AsyncCallback<void>): void;
translate(x: number, y: number): Promise<void>;

示例:

await pixelMap.translate(3.0, 1.0);

13.rotate

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何根据输入的角度对图片进行旋转。

通过调用rotate对图片进行旋转。

rotate(angle: number, callback: AsyncCallback<void>): void;
rotate(angle: number): Promise<void>;

示例:

await pixelMap.rotate(90.0);

14.flip

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何根据输入的条件对图片进行翻转。

通过调用flip对图片进行翻转。

flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback<void>): void;
flip(horizontal: boolean, vertical: boolean): Promise<void>;

示例:

await pixelMap.flip(false, true);

15.crop

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何根据输入的尺寸对图片进行裁剪。

通过调用crop对图片进行裁剪。

crop(region: Region, callback: AsyncCallback<void>): void;
crop(region: Region): Promise<void>;

示例:

await pixelMap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });

16.release

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何释放pixelmap实例。

通过调用release释放pixelmap。

1.使用create通过属性创建pixelmap。

image.createPixelMap(color, opts, pixelmap =>{}

2.使用release释放pixelmap实例

pixelmap.release(()=>{
            expect(true).assertTrue();
            console.log('TC_027-1 suc');
            done();
        })  

17.getImageInfo

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何根据特定数字获取图片信息。

getImageInfo(index: number, callback: AsyncCallback<ImageInfo>): void;
getImageInfo(callback: AsyncCallback<ImageInfo>): void;
getImageInfo(index?: number): Promise<ImageInfo>;

1.创建imagesource。

const imageSourceApi = image.createImageSource('/sdcard/test.jpg')

2.获取图片信息。

imageSourceApi.getImageInfo((imageInfo) => {
        console.info('TC_045 imageInfo')
        expect(imageInfo !== null).assertTrue()
        done()
      })

18.getImageProperty

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何根据索引获取图像的指定属性键的值。

getImageProperty(key:string, options?: GetImagePropertyOptions): Promise<string>;
getImageProperty(key:string, callback: AsyncCallback<string>): void;

19.modifyImageProperty

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何通过指定的键修改图片属性的值。

modifyImageProperty(key: string, value: string): Promise<void>;
modifyImageProperty(key: string, value: string, callback: AsyncCallback<void>): void;

20.createPixelMap

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何创建pixelmap实例。

1.使用createImageSource创建图片源。

const imageSourceApi = image.createImageSource('/sdcard/test.jpg')

2.使用createPixelMap创建pixelmap

imageSourceApi.createPixelMap(decodingOptions, (pixelmap) => {})

21.updateData

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何更新图片数据源。

updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number): Promise<void>;
updateData(buf: ArrayBuffer, isFinished: boolean, value: number, length: number, callback: AsyncCallback<void>): void;

1.使用CreateIncrementalSource创建imagesource。

const dataBuffer = new ArrayBuffer(96)
const imageSourceIncrementalSApi = image.CreateIncrementalSource(dataBuffer)

2.使用updateData更新图片源。

imageSourceIncrementalSApi.updateData(array, false, (error, data) => {})

22.release

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何释放图片源实例。

release(callback: AsyncCallback<void>): void;
release(): Promise<void>;

23.packing

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何压缩图片。

packing(source: ImageSource, option: PackingOption, callback: AsyncCallback<ArrayBuffer>): void;
packing(source: ImageSource, option: PackingOption): Promise<ArrayBuffer>;
packing(source: PixelMap, option: PackingOption, callback: AsyncCallback<ArrayBuffer>): void;
packing(source: PixelMap, option: PackingOption): Promise<ArrayBuffer>;

1.使用createImageSource创建图片源。

const imageSourceApi = image.createImageSource('/sdcard/test.png')

2.创建packer实例。

imagePackerApi.packing(imageSourceApi, packOpts).then((data) => {})

24.release

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何释放packer实例。

release(callback: AsyncCallback<void>): void;
release(): Promise<void>;

1.使用createImagePacker创建packer实例。

const imagePackerApi = image.createImagePacker()

2.使用release释放packer实例。

imagePackerApi.release()

25.getReceivingSurfaceId

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何获取surface id供Camera或其他组件使用。

getReceivingSurfaceId(): Promise<string>;
getReceivingSurfaceId(callback: AsyncCallback<string>): void;

示例:

receiver.getReceivingSurfaceId().then( id => { } )

26.readLatestImage

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何读取最新的图片。

readLatestImage(callback: AsyncCallback<Image>): void;
readLatestImage(): Promise<Image>;

示例:

receiver.readLatestImage().then(img => { })

27.readNextImage

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何读取下一张图片。

readNextImage(callback: AsyncCallback<Image>): void;
readNextImage(): Promise<Image>;

示例:

receiver.readNextImage().then(img => {})

28.on

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何接收图片时注册回调。

on(type: 'imageArrival', callback: AsyncCallback<void>): void;

示例:

receiver.on('imageArrival', () => {})

29.release

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何释放receiver实例。

release(callback: AsyncCallback<void>): void;
release(): Promise<void>;

1.使用createImageReceiver创建receiver实例。

const imageReceiverApi = image.createImageReceiver()

2.使用release释放packer实例。

imageReceiverApi.release()

30.getComponent

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何根据图像的组件类型从图像中获取组件缓存。

getComponent(componentType: ComponentType, callback: AsyncCallback<Component>): void;
getComponent(componentType: ComponentType): Promise<Component>;

示例:

img.getComponent(4).then(component => { })

31.release

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何释放image实例。

release(callback: AsyncCallback<void>): void;
release(): Promise<void>;

32.CreateIncrementalSource

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何创建增量imagesource。

CreateIncrementalSource(buf: ArrayBuffer): ImageSource;
CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource;

1.创建buffer。

const data = new ArrayBuffer(96)

2.使用CreateIncrementalSource创建imagesource。

const imageSourceApi = image.CreateIncrementalSource(data)

33.创建ImageSource实例

image提供了操作imagesource的接口,如创建、读取和删除,以下展示了如何通过不同方式创建imagesource。

1.通过文件路径创建imagesource。

createImageSource(uri: string): ImageSource;
createImageSource(uri: string, options: SourceOptions): ImageSource;

示例:

const imageSourceApi = image.createImageSource('/sdcard/test.jpg');

2.通过fd创建imagesource。

createImageSource(fd: number): ImageSource;
createImageSource(fd: number, options: SourceOptions): ImageSource;

示例:

const imageSourceApi = image.createImageSource(fd);

3.通过buffer创建imagesource。

createImageSource(buf: ArrayBuffer): ImageSource;
createImageSource(buf: ArrayBuffer, options: SourceOptions): ImageSource;

示例:

const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data);

34.创建PixelMap实例

image提供了操作pixelmap的接口,如创建、读取和删除,以下展示了如何通过属性创建pixelmap。

createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise<PixelMap>;
createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback<PixelMap>): void;

1.设置属性。

const Color = new ArrayBuffer(96)
let opts = {
  alphaType: 0,
  editable: true,
  pixelFormat: 4,
  scaleMode: 1,
  size: { height: 2, width: 3 },
}

2.调用createpixelmap通过属性创建pixelmap实例。

image.createPixelMap(Color, opts)
      .then((pixelmap) => {
        expect(pixelmap !== null).assertTrue()
        console.info('Succeeded in creating pixelmap.')
        done()
      })

35.创建imagepacker实例

image提供了操作imagepacker的接口,以下展示了如何通过属性创建imagepacker。

createImagePacker(): ImagePacker;

1.创建imagesource。

const imageSourceApi = image.createImageSource('/sdcard/test.png')

2.创建imagepacker。

const imagePackerApi = image.createImagePacker()

36.创建imagereceiver实例

image提供了操作imagereceiver的接口,以下展示了如何通过属性创建imagereceiver。

createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver;

相关仓

multimedia_image_framework

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS

简介

暂无描述 展开 收起
C++ 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/openharmony/multimedia_image_framework.git
git@gitee.com:openharmony/multimedia_image_framework.git
openharmony
multimedia_image_framework
multimedia_image_framework
master

搜索帮助