Want to build a Photo Editing App with HMS Image Kit Vision Service?

Firuze Gümüş
Huawei Developers
Published in
4 min readJul 20, 2020

Image Kit Vision Service of HMS (Huawei Mobile Services) offers us very stylish filters to build a photo editor app. In this article, we will design a nice filtering screen using Vision Service. Moreover, it will be very easy to develop and it will allow you to make elegant beauty apps.

The Image Vision service provides 24 color filters for image optimization. It renders the images you provide and returns them as filtered bitmap objects.

Requirements :

Huawei Phone (It doesn’t support non-Huawei Phones)

EMUI 8.1 or later (Min Android SDK Version 26)

Restrictions :

When using the filter function of Image Vision, make sure that the size of the image to be parsed is not greater than 15 MB, the image resolution is not greater than 8000 x 8000, and the aspect ratio is between 1:3 and 3:1. If the image resolution is greater than 8000 x 8000 after the image is decompressed by adjusting the compression settings or the aspect ratio is not between 1:3 and 3:1, a result code indicating parameter error will be returned. In addition, a larger image size can lead to longer parsing and response time as well as higher memory and CPU usage and power consumption.

Let’s start to build a nice filtering screen. First of all, please follow these steps to create a regular app on App Gallery.

Then we need to add dependencies to the app level gradle file. (implementation ‘com.huawei.hms:image-vision:1.0.2.301’)

Don’t forget to add agconnect plugin. (apply plugin: ‘com.huawei.agconnect’)

Add maven repo url and agconnect dependency to the project level gradle file.

After added dependencies, we need to create an ImageVision instance to perform related operations such as obtaining the filter effect. From now on, you can initialize the service.

Our app is allowed to use the Image Vision service only after the successful verification. So we should provide an authJson object with app credentials. The value of initCode must be 0, indicating that the initialization is successful.

Select an image from the Gallery. Call Init filter method and then start filtering images one by one which are located in recyclerView.

In our scenario, a user clicks a filter to render the selected image we provide and the Image Vision Result object returns the filtered bitmap. So we need to implement onSelected method of the interface to our activity which gets the FilterItem object of the clicked item from the adapter.

More information about the parameters can be found in the table below.

FilterType codes of 24 different filters as follows:

When the user opens the gallery and selects an image from a directory, we will produce 24 different filtered versions of the image. I used async coroutine channels to render images with first in first out manner. So we can obtain the filter images one by one. Using Image Vision Service with Kotlin Coroutines is so fast and performance-friendly.

To turn off hardware acceleration, configure the AndroidManifest.xml file as follows:

If you do not need to use filters any longer, call the imageVisionAPI.stop() API to stop the Image Vision service. If the returned stopCode is 0, the service is successfully stopped.

We have designed an elegant filtering screen quite easily. Preparing a filter page will no longer take your time. You will be able to develop quickly without having to know OpenGL. You should try Image Kit Vision Service as soon as possible.

And the result :

For more information about HMS Image Kit Vision Service please refer to :

--

--