[Huawei Developers] John Wo:
Introduction

HUAWEI Image Kit provides smart image editing, designing and animating capabilities into your application. It provides Image Vision service for 24 unique colour filters, 9 smart layouts as well as the image theme tagging, text arts, image cropping and many more functionalities. It also provide Image rendering service for five basic animations and nine advance animations capabilities.

It provides two SDKs, Image Vision SDK and Image Render SDK.

Image Vision service APIs to implement functions such as filter, smart layout, sticker, theme tagging and image cropping.

Image Render service APIs to implement basic and advanced animation effects.

Software Requirements

Java JDK 1.8 or later

Android API Level 26 or higher

EMUI 8.1 or later (applicable to the SDK, but not the fallback-SDK)

HMS Core (APK) 4.0.2.300 or later (applicable to the SDK, but not the fallback-SDK)

Functions

Basic Animations

Advanced Animations

Image Editing

Integration Preparations

To integrate HUAWEI Image Kit, you must complete the following preparations:

Register as a developer.

Create an Android Studio project.

Generate a signing certificate fingerprint.

Configure the signing certificate fingerprint on AG Console.

Integration steps

In this article we are going to implement filter service, although Image Vision provides five major functionalities which is most commonly used by image editing application and many more.

First, we need to add the Image Vision SDK dependencies in app build.gradle file.

dependencies {
...
implementation 'com.huawei.hms:image-vision:1.0.3.301'
implementation 'com.huawei.hms:image-vision-fallback:1.0.3.301'
...
}

Note: Image Kit works only on a device running Android 8.0 or later.

For initializing the service. call setVisionCallBack during service initialization, your app must implement the ImageVision. VisionCallBack API and override its onSuccess(int successCode) and onFailure(int errorCode) methods.

ImageVisionImpl imageVisionAPI = ImageVision.getInstance(this);

imageVisionAPI.setVisionCallBack(new ImageVision.VisionCallBack() {
@Override
public void onSuccess(int successCode) {
int initCode = imageVisionAPI.init(context, authJson);
...
}
@Override
public void onFailure(int errorCode) {
...
}
});

After Initializing the service select the Image from gallery :

public static void getByAlbum(Activity act) {
Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
String[] mimeTypes = {"image/jpeg", "image/png", "image/webp"};
getAlbum.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
getAlbum.setType("image/*");
getAlbum.addCategory(Intent.CATEGORY_OPENABLE);
act.startActivityForResult(getAlbum, 801);
}

Note: The image size should not be greater than 15 MB, resolution should not be greater than 8000 x 8000 pixel and the aspect should be in between 1:3 to 3:1.

There are 24 different colour filters provided by Filter Service. For each type of filter we have separate respective mapping code. Image Vision will return a bitmap filtered by one of these 24 colour filters.

Make sure that we call the getColorFilter() API in the background thread. For calling the filter API, you need to specify the bitmap of the image to be processed and the filter effect and set the filtered image on imageView.

//Obtain the rendering result from visionResult.
new Thread(new Runnable() {
@Override
public void run() {
ImageVisionResult visionResult = imageVisionAPI.getColorFilter(requestJson,imageBitmap);
}
}).start();

After getting the filtered result, If you do not want 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.

if (null != imageVisionFilterAPI) {
int stopCode = imageVisionFilterAPI.stop();
}

More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0203429680523150041