• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2025 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
16import effectKit from '@ohos.effectKit';
17import image from '@ohos.multimedia.image';
18
19
20function main() {
21  console.log('Test effectKit start');
22  const opts: image.InitializationOptions = {
23    size: { width: 480, height: 360 },
24    editable: true,
25    pixelFormat: image.PixelMapFormat.BGRA_8888,
26  };
27  let pixelMap: image.PixelMap = image.createPixelMapSync(opts);
28  if (pixelMap == undefined) {
29    console.log('Create image.createPixelMapSync failed');
30    return;
31  }
32  console.log('Create image.createPixelMapSync success');
33  let headFilter: effectKit.Filter = effectKit.createEffect(pixelMap);
34  if (headFilter == undefined) {
35    console.log('Test createEffect failed');
36    return;
37  }
38  console.log('Test createEffect success');
39  let blurFilter: effectKit.Filter = headFilter.blur(10);
40  if (blurFilter == undefined) {
41    console.log('Test blur failed');
42    return;
43  }
44  console.log('Test blur success');
45  blurFilter.getEffectPixelMap().then((pixelMap: image.PixelMap) => {
46    if (pixelMap != undefined) {
47      console.log('Test getEffectPixelMap success, getPixelBytesNumber = ', pixelMap.getPixelBytesNumber());
48    }
49  }).catch((ex: Object | null | undefined) => {
50    console.error('Test getEffectPixelMap failed');
51  });
52  console.log('Test effectKit end');
53}