W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
圖像效果提供處理圖像的一些基礎(chǔ)能力,包括對當(dāng)前圖像的亮度調(diào)節(jié)、模糊化、灰度調(diào)節(jié)、智能取色等。
該模塊提供以下圖像效果相關(guān)的常用功能:
本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
createEffect(source: image.PixelMap): Filter
通過傳入的PixelMap創(chuàng)建Filter實(shí)例。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
source | 是 | image模塊創(chuàng)建的PixelMap實(shí)例??赏ㄟ^圖片解碼或直接創(chuàng)建獲得,具體可見圖片開發(fā)指導(dǎo)。 |
返回值:
類型 | 說明 |
---|---|
返回不帶任何效果的Filter鏈表的頭節(jié)點(diǎn),失敗時(shí)返回null。 |
示例:
- import image from "@ohos.multimedia.image";
- const color = new ArrayBuffer(96);
- let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
- image.createPixelMap(color, opts).then((pixelMap) => {
- let headFilter = effectKit.createEffect(pixelMap);
- })
createColorPicker(source: image.PixelMap): Promise<ColorPicker>
通過傳入的PixelMap創(chuàng)建ColorPicker實(shí)例,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
source | 是 | image模塊創(chuàng)建的PixelMap實(shí)例。可通過圖片解碼或直接創(chuàng)建獲得,具體可見圖片開發(fā)指導(dǎo)。 |
返回值:
類型 | 說明 |
---|---|
Promise<ColorPicker> | Promise對象。返回創(chuàng)建的ColorPicker實(shí)例。 |
示例:
- import image from "@ohos.multimedia.image";
- const color = new ArrayBuffer(96);
- let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
- image.createPixelMap(color, opts).then((pixelMap) => {
- effectKit.createColorPicker(pixelMap).then(colorPicker => {
- console.info("color picker=" + colorPicker);
- }).catch(ex => console.error(".error=" + ex.toString()))
- })
createColorPicker(source: image.PixelMap, callback: AsyncCallback<ColorPicker>): void
通過傳入的PixelMap創(chuàng)建ColorPicker實(shí)例,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
source | 是 | image模塊創(chuàng)建的PixelMap實(shí)例。可通過圖片解碼或直接創(chuàng)建獲得,具體可見圖片開發(fā)指導(dǎo)。 | |
callback | AsyncCallback<ColorPicker> | 是 | 回調(diào)函數(shù)。返回創(chuàng)建的ColorPicker實(shí)例。 |
示例:
- import image from "@ohos.multimedia.image";
- const color = new ArrayBuffer(96);
- let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
- image.createPixelMap(color, opts).then((pixelMap) => {
- effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
- if (error) {
- console.error('Failed to create color picker.');
- } else {
- console.info('Succeeded in creating color picker.');
- }
- })
- })
顏色類,用于保存取色的結(jié)果。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
red | number | 是 | 否 | 紅色分量值,取值范圍[0x0, 0xFF]。 |
green | number | 是 | 否 | 綠色分量值,取值范圍[0x0, 0xFF]。 |
blue | number | 是 | 否 | 藍(lán)色分量值,取值范圍[0x0, 0xFF]。 |
alpha | number | 是 | 否 | 透明通道分量值,取值范圍[0x0, 0xFF]。 |
取色類,用于從一張圖像數(shù)據(jù)中獲取它的主要顏色。在調(diào)用ColorPicker的方法前,需要先通過createColorPicker創(chuàng)建一個(gè)ColorPicker實(shí)例。
getMainColor(): Promise<Color>
讀取圖像主色的顏色值,結(jié)果寫入Color里,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
返回值:
類型 | 說明 |
---|---|
Promise<Color> | Promise對象。返回圖像主色對應(yīng)的顏色值,失敗時(shí)返回錯(cuò)誤信息。 |
示例:
- colorPicker.getMainColor().then(color => {
- console.info('Succeeded in getting main color.');
- console.info(`color[ARGB]=${color.alpha},${color.red},${color.green},${color.blue}`);
- }).catch(error => {
- console.error('Failed to get main color.');
- })
getMainColorSync(): Color
讀取圖像主色的顏色值,結(jié)果寫入Color里,使用同步方式返回。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
返回值:
類型 | 說明 |
---|---|
Color實(shí)例,即圖像主色對應(yīng)的顏色值,失敗時(shí)返回null。 |
示例:
- let color = colorPicker.getMainColorSync();
- console.info('get main color =' + color);
blur(radius: number): Filter
將模糊效果添加到效果鏈表中,結(jié)果返回效果鏈表的頭節(jié)點(diǎn)。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
radius | number | 是 | 模糊半徑,單位是像素。模糊效果與所設(shè)置的值成正比,值越大效果越明顯。 |
返回值:
類型 | 說明 |
---|---|
返回已添加的圖像效果。 |
示例:
- import image from "@ohos.multimedia.image";
- const color = new ArrayBuffer(96);
- let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } };
- image.createPixelMap(color, opts).then((pixelMap) => {
- let radius = 5;
- let headFilter = effectKit.createEffect(pixelMap);
- if (headFilter != null) {
- headFilter.blur(radius);
- }
- })
brightness(bright: number): Filter
將高亮效果添加到效果鏈表中,結(jié)果返回效果鏈表的頭節(jié)點(diǎn)。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
bright | number | 是 | 高亮程度,取值范圍在0-1之間,取值為0時(shí)圖像保持不變。 |
返回值:
類型 | 說明 |
---|---|
返回已添加的圖像效果。 |
示例:
- import image from "@ohos.multimedia.image";
- const color = new ArrayBuffer(96);
- let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } };
- image.createPixelMap(color, opts).then((pixelMap) => {
- let bright = 0.5;
- let headFilter = effectKit.createEffect(pixelMap);
- if (headFilter != null) {
- headFilter.brightness(bright);
- }
- })
grayscale(): Filter
將灰度效果添加到效果鏈表中,結(jié)果返回效果鏈表的頭節(jié)點(diǎn)。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
返回值:
類型 | 說明 |
---|---|
返回已添加的圖像效果。 |
示例:
- import image from "@ohos.multimedia.image";
- const color = new ArrayBuffer(96);
- let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } };
- image.createPixelMap(color, opts).then((pixelMap) => {
- let headFilter = effectKit.createEffect(pixelMap);
- if (headFilter != null) {
- headFilter.grayscale();
- }
- })
getPixelMap(): image.PixelMap
獲取已添加鏈表效果的源圖像的image.PixelMap。
系統(tǒng)能力: SystemCapability.Multimedia.Image.Core
返回值:
類型 | 說明 |
---|---|
已添加效果的源圖像的image.PixelMap。 |
示例:
- import image from "@ohos.multimedia.image";
- const color = new ArrayBuffer(96);
- let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } };
- image.createPixelMap(color, opts).then((pixelMap) => {
- let pixel = effectKit.createEffect(pixelMap).grayscale().getPixelMap();
- })
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: