JetBrains / skija

Java bindings for Skia
Apache License 2.0
2.63k stars 127 forks source link

Animation with image #129

Closed justicezxz closed 3 years ago

justicezxz commented 3 years ago

hi, how to render animation with image? use json file containing Base64 pictures. I found that skia can do it.

thanks

tonsky commented 3 years ago

what format are those pictures in? after base64 decoding?

justicezxz commented 3 years ago

Yes, like this JSON file https://skottie.skia.org/c16eee287f2cea44102b6670c66e60ab?h=1000&w=1000

tonsky commented 3 years ago

Ok, this format is Lottie. We have an example scene here https://github.com/JetBrains/skija/blob/master/examples/scenes/src/SkottieScene.java

justicezxz commented 3 years ago

Yes, I tried, but the picture in JSON is not displayed

xiaoxiao-wzj commented 3 years ago

hi, I also encountered this problem, if there are pictures in json, how can I load pictures

tonsky commented 3 years ago

If you share your source code I might be able to help you

justicezxz commented 3 years ago

just run the example with this json file looks like image resource is not loaded

json.txt

tonsky commented 3 years ago

Oh, I see. I think those are just not supported in Skia. You can open an issue here https://bugs.chromium.org/p/skia/issues/list?q=Area%3DSkottie&can=2

xiaoxiao-wzj commented 3 years ago

image

For pictures, skija needs to add ResourceProvider to specify the way to load resources, just like fonts

justicezxz commented 3 years ago

please add these two lines in AnimationBuilder.cc

extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skija_skottie_AnimationBuilder__1nBuildFromFile
  (JNIEnv* env, jclass jclass, jlong ptr, jstring pathStr) {
    Animation::Builder* instance = reinterpret_cast<Animation::Builder*>(static_cast<uintptr_t>(ptr));
    SkString path = skString(env, pathStr);
    auto resource_provider =
        skresources::CachingResourceProvider::Make(
            skresources::DataURIResourceProviderProxy::Make(
                skresources::FileResourceProvider::Make(SkOSPath::Dirname(path.c_str()),
                                                        /*predecode=*/true),
                /*predecode=*/true));
    instance->setResourceProvider(std::move(resource_provider));
    sk_sp<Animation> animation = instance->makeFromFile(path.c_str());
    return reinterpret_cast<jlong>(animation.release());
}
tonsky commented 3 years ago

I’ll take a look next week!

tonsky commented 3 years ago

I’ve added all three resource providers as classes to skija.resources package. See https://github.com/JetBrains/skija/blob/e265802686173485b3cc03bf6c9dca2fd364a5ed/examples/scenes/src/SkottieScene.java#L43 for an example. Source code is here, but for jars there have been some maven deployment issues, hopefully will fix them next week

tonsky commented 3 years ago

Deployed as 0.93.4