MCPcopy Create free account
hub / github.com/Tencent/tgfx / AddImageFromEncoded

Function AddImageFromEncoded

ohos/hello2d/src/main/cpp/napi_init.cpp:29–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29static napi_value AddImageFromEncoded(napi_env env, napi_callback_info info) {
30 size_t argc = 2;
31 napi_value args[2] = {nullptr};
32 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
33 size_t strSize;
34 char srcBuf[2048];
35 napi_get_value_string_utf8(env, args[0], srcBuf, sizeof(srcBuf), &strSize);
36 std::string name = srcBuf;
37 size_t length;
38 void* data;
39 auto code = napi_get_arraybuffer_info(env, args[1], &data, &length);
40 if (code != napi_ok) {
41 return nullptr;
42 }
43 auto tgfxData = tgfx::Data::MakeWithCopy(data, length);
44 if (appHost == nullptr) {
45 appHost = CreateAppHost();
46 }
47 appHost->addImage(name, tgfx::Image::MakeFromEncoded(tgfxData));
48 return nullptr;
49}
50
51static void Draw(int index, float zoom = 1.0f, float offsetX = 0.0f, float offsetY = 0.0f) {
52 if (window == nullptr || appHost == nullptr || appHost->width() <= 0 || appHost->height() <= 0) {

Callers

nothing calls this directly

Calls 2

CreateAppHostFunction · 0.70
addImageMethod · 0.45

Tested by

no test coverage detected