Article source: Blog | HMS Core

A “cold” knowledge, and double 叒 Yi to the Chinese Valentine’s Day!

At this time of year, gift-giving guides are flying around, making it difficult to make choices. It’s a wonder that people who are able to find love are struggling with gift-giving.

​​

​​

Want me to say, this valentine’s day romantic festival, the most important thing is to figure an atmosphere! Today I would like to introduce you to a programmer for the Tanabata “full of atmosphere” small gift – with the help of Huawei image services, the development of a super love Tanabata GIFs, it supports input special keywords, trigger the “Tanabata” effects; At the same time, the picture can also follow the finger touch to produce motion effect…

Have the object of the show to the object to see, single friends can also do a Tanabata atmosphere group members first, the method to hand, maybe the next time to use.

No more words, open up!

Development steps

1. Key word animation playback

Step 1: Material preparation

First, find a suitable picture. Here we choose a picture of the Cowherd and the Weaver girl:

​​

​​

Then take the animated parts out of the picture. We took out the clouds, the cowherd, the weaver girl and the red heart.

Step 2: Prepare for integration

To complete the developer registration, create the application, and sign the configuration, follow these instructions:

Developer.huawei.com/consumer/cn…

Then configure the repository and build dependencies as follows:

In the project level “build.gradle” file, configure:

​​

​​

Configure compile dependencies (current version 1.0.3.301) in the application-level “build.gradle” file:

​​

​​

Configure permissions

Configure permissions for the application in the Androidmanifest.xml file.

​​

​​

Step 3: Feature development

1. Interface design

Here uses the simplest interface, a FrameLayout configuration input box and button:

​​

​​

We will debug and render the animation in this FrameLayout.

2. Configure storage permission application

In the onCreate() method of the MainActivity, check whether WRITE_EXTERNAL_STORAGE permission is available. If not, call the requestPermission method to apply for WRITE_EXTERNAL_STORAGE permission:

​​

​​

Initialize the Image rendering module if the permission exists or after the permission application is successful

​​

​​

3.Image rendering module initialization

Get the render instance, initialize, and get the render view. This specifies the directory of animated elements:

​​

​​

4. Configure the keyword playback animation

Remember the input fields and buttons I left behind? We use the keyword “Love” to animate the play. Only need through imageRenderAPI. PlayAnimation () can trigger:

​​

​​

5. Configure animation

Now that the frame is set up, it’s time for the animation. Image Kit provides five basic and nine advanced motion effects that can be used in most scenarios.

Here we use the transparency animation, the shift animation, the zoom animation, and the fall animation.

The animation configuration for Image Kit is done in the manifest.xml file. Not to be confused with the AndroidManifest.xml file.

First, configure the virtual screen width and background image. After the virtual screen width is configured, the system zooms and scales the animation based on different resolutions to ensure the same effect.

​​

​​

We hope that the Cowherd and the Weaver Girl can gradually get close to each other until they meet. At this time, two elements of the Cowherd and the Weaver Girl are added, and moving lines are configured respectively. At this time, the special effects of moving paintings are used in place:

​​

​​

So the Cowherd and the Weaver will be close to the middle from both sides of the screen until they meet.

After meeting, there will be a beating heart in the center, using the opacity animation and zoom animation overlay effects:

​​

​​

By now, the key elements are in place, but they still look a little dry and need some embellishment.

The clouds in the sky can also move, making it more flexible in small areas:

​​

​​

To make it more romantic, sprinkle some petals, and here’s the falling motion:

​​

​​

So we’re done here. You can save the animation at the end

​​

​​

That’s the end result

In addition to motion effects, Image Kit also provides filters to add a romantic touch to images, and features such as stickers and characters to add a romantic element to users’ images.

For those who are ready to learn programming, if you want to better improve your core programming ability (internal skills) might as well start now!

C language C++ programming learning communication circle, QQ group: [614504899] wechat public number: C language programming learning base

Collation and sharing (years of learning source code, actual project video, project notes, basic introduction tutorial)

Welcome to change and learn programming partners, use more information to learn to grow faster than their own oh!