In the last post on how to add photo-editing capabilities to your app: cropping, filtering, decals, typography, and tags, we went into detail about the “dilemma” that various apps face when it comes to “images” : Due to the lack of image editing and design capabilities within the app, or the lack of image editing and design capabilities provided by the app, high-quality apps with powerful functions cannot improve user retention rate and affect the competitive strength of the app itself. Huawei Image Services aims to solve this problem for all kinds of interactive applications, which can be said to be born in response to the situation. Based on the detailed introduction of the five image editing capabilities of Huawei image service, their application scenarios and functional values, the following will bring you the specific development steps of the five image editing functions.

Filter service



Development steps

Filter service development steps are as follows. You need to provide images and related parameters to get the corresponding return values.

1. Import Filter Service Pack.

Java code

import com.huawei.hms.image.vision.*;    
import com.huawei.hms.image.vision.bean.ImageVisionResult;

2. Get the filter service instance.

Java code

// Get ImageVisionImpl object ImageVisionImpl ImageVisionApi = ImageVision.getInstance(this);

3, service initialization, the need when invoking setVisionCallBack ImageVision. VisionCallBack interface, rewrite the onSuccess (int successCode) and onFailure (int errorCode) method.

Upon successful initialization, the framework calls back to the onSuccess method, in which the filter service needs to be initialized again. When calling the filter initialization interface, third-party applications can use the filter service only after passing the validation. The initCode must be 0, and the filter service is initialized successfully.

When the framework fails to initialize, it calls back the onFailure method, returning the failure error code.

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

The ginseng authJson:

Note: Intelligent text and text typesetting service, image theme label service token is a required value, the access method is referred to: token access method.

Build parameter pair filter service requestJSON example: image.



RequestJSON field information:

TaskJSON filter field information:

FilterType mapping table:

AuthJSON mapping table: See the AuthJSON table.

Example filter service requestJSON:

{ "requestId":"requestId", "taskJson":{"intensity":"1","filterType":"1","compressRate":"1"}, "authJson":{"projectId":"projectIdTest","appId":"appIdTest","authApiKey":"authApiKeyTest","clientSecret":"CSecretTest"," clientId":"CIdTest","token":"tokenTest"} }

5. The filter service gets the results.

When you call the GetColorFilter interface, you need to enter the Bitmap of the image to be processed and select the desired filter effect. After processing the original image according to the parameters passed in, the filter service returns the Bitmap of the processed image.

Java code

New Thread(new Runnable() {@Override public void run() {ImageVisionResult VisionResult = imageVisionAPI.getColorFilter(requestJson,imageBitmap); } }).start();

VisionResult return value:

Response field information:

Note: When calling the GetColorFilter interface, it needs to start a child thread to execute, and cannot execute in the main thread.

6. Discontinuation of service.

When the filter effect is no longer needed, the interface is called to stop the service. When stopCode is 0, the service is stopped successfully.

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

The development steps of intelligent typesetting service are as follows. You need to provide pictures and relevant parameters to get the corresponding return value.

1. Import the intelligent typesetting service package.

import com.huawei.hms.image.vision.bean.ImageLayoutInfo ; import com.huawei.hms.image.vision.*;

2. Obtain an example of intelligent typesetting service.

// Get ImageVisionImpl object ImageVisionImpl ImageVisionApi = ImageVision.getInstance(this);

3. Service initialization, consistent with filter service, as described in the development steps.

Build the parameter object.

TaskJSON field information for intelligent layout of text and text:

Note that in StyleList, Info8 is formatted in vertical format, currently only Chinese format is supported, and no other language format is supported. Info3 is the default cover layout; If the user enters Info8 and the input labels and text descriptions are in non-Chinese languages, the user’s Info3 format is returned. AuthJSON mapping table: See the AuthJSON field definition. RequestJSON example of an intelligent graphic typesetting service: Java code

{ "requestId":"requestId", "TaskJSON ":{"title":" light luxury new generation ","description":" far away from the noise of the city ","copyRight":" huawei magazine lock screen ","isNeedMask":false,"anchor":" view details ","styleList": ["info1"]}, "authJson":{"projectId":"projectIdTest","appId":"appIdTest","authApiKey":"authApiKeyTest","clientSecret":"CSecretTest"," clientId":"CIdTest","token":"tokenTest"}}

5. Obtaining results of intelligent typesetting services. When the AnalyzeImageLayout interface is called, it needs to input the Bitmap of the image to be processed and select the style and text to be added (build parameters). The intelligent typesetting service needs to be connected to the Internet. If not, it will revert to the Info3 style by default. The Intelligent Graphic Typography service returns the ImageLayoutInfo wrapper class and draws the view based on the parameters of the wrapper class (see how the sample code is drawn).

New Thread(new Runnable() {@Override public void run() {ImageLayoutInfo ImageLayoutInfo = imageVisionAPI.analyzeImageLayout(requestJson, imageBitmap); } }).start();

ImageLayoutInfo return value:

The response field:

Note: ① Because the interface involves a network request, it is necessary to open a child thread to call the interface. ② When using the intelligent typesetting service, you need to ensure that the token provided is valid, otherwise you cannot use the service. ③ The token acquisition method can be referred to the token acquisition method. 6. Discontinuation of service. When the intelligent typesetting effect of text and text is no longer needed, the interface is called to stop the service. When stopCode is 0, the execution succeeds.

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

The original link: https://developer.huawei.com/… Author: Pepper