HarmonyOS NAPI调用ArkTS的静态方法

如何通过NAPI发起对ArkTS类静态方法对调用?

例如有如下静态ArkTS类方法:

class ImageProcess { 
  static getTransformedBitmap(localImageFilePath: string, rotate: number): ArrayBuffer { 
    // rotate the image and returns image data as an array buffer 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

NAPI调用ArkTS类方法:

void callStaticJSFunc(napi_env env) { 
  // how to find and call ImageProcess.getTransformedBitmap(path, 90)? 
}
  • 1.
  • 2.
  • 3.
HarmonyOS
2024-08-27 11:38:26
889浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

可以使用Aki三方库来实现C++对ets静态方法调用,参考代码如下:

index.ets

import testAki from 'libentry.so'; 
class ImageProcess { 
  static foo(): string { 
    return "this is foo" 
  } 
} 
@Entry 
@Component 
struct Index { 
  @State message: string = 'bind function'; 
  build() { 
    Column({ space: 4 }) { 
      Row() { 
        Text('Native访问ArkTS静态方法') 
          .fontSize(12) 
          .fontWeight(FontWeight.Bold) 
        Button('点击调用') 
          .onClick(() => { 
            testAki.callArkTSStaticMethod(ImageProcess) 
          }) 
      } 
      .width('100%') 
      .justifyContent(FlexAlign.SpaceBetween) 
    } 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
分享
微博
QQ
微信
回复
2024-08-27 17:59:42
相关问题
native侧如何调用静态方法
1571浏览 • 1回复 待解决
HarmonyOS调用napi_call_function方法时崩溃
1608浏览 • 1回复 待解决
C++调用ArkTS 定义方法
3267浏览 • 1回复 待解决
HarmonyOS 怎么调用C语言.a静态
1424浏览 • 1回复 待解决
在Native侧调用ArkTS全局普通方法
1809浏览 • 1回复 待解决
HarmonyOS native怎样调用ArkTS自定义方法
841浏览 • 1回复 待解决
native侧如何使用类静态方法
1252浏览 • 1回复 待解决
HarmonyOS NAPI调用HAR模块失败
1499浏览 • 1回复 待解决
求告知静态订阅相关方法
1574浏览 • 1回复 待解决