Teach you to easily integrate the graphic layout function of Huawei Image Kit

Preface

Currently, Huawei Image Kit's graphic typesetting function provides users with 9 smart typesetting styles. The typesetting methods are divided into two layouts: the content is equal width and the content is unequal width. Users can choose the appropriate typesetting according to their own picture style.

Application scenario

In the layout of our e-magazine, there are many materials that need to be added with text. At this time, in order to improve work efficiency, the layout method of image kit can be satisfied, and the layout can be quickly formed. This also adds literary and artistic features to users' viewing of pictures.

Development combat

The actual development of this time is to realize the realization of graphic typesetting.

Development preparation

Developers need to provide pictures and related parameters to get the corresponding return value.

Step 1: Import the graphic intelligent typesetting service package.
import   com.huawei.hms.image.vision.bean.ImageLayoutInfo ;
import   com.huawei.hms.image.vision.*;
Step 2: Obtain an example of the graphic intelligent typesetting service.
// 获取ImageVisionImpl 对象
 ImageVisionImpl imageVisionAPI   = ImageVision.getInstance(this);
Step 3: Service initialization, consistent with the filter service, please refer to the relevant description in the development steps.
Step 4: Build the parameter object.

Insert picture description here

requestJson field information:

Insert picture description here

TaskJson field information of graphic intelligent typesetting:

Insert picture description here

authJson mapping table: see authJson field definition.

Example of requestJson for graphic intelligent typesetting service:

{
  "requestId":"requestId",
  "taskJson":{"title":"轻奢新生代","description":"远离城市的喧嚣","copyRight":"华为杂志锁屏","isNeedMask":false,"anchor":"查看详情","styleList":["info1"]},  "authJson":{"projectId":"projectIdTest","appId":"appIdTest","authApiKey":"authApiKeyTest","clientSecret":"CSecretTest","clientId":"CIdTest","token":"tokenTest"}
}
Step 5: Get the result of the graphic intelligent typesetting service.

When the developer calls the graphic intelligent typesetting interface, he needs to input the bitmap of the image to be processed and select the style and text to be added (construction parameters). The graphic intelligent typesetting service needs to be connected to the Internet. If not, the info3 style will be returned by default. The graphic intelligent typesetting service will return the ImageLayoutInfo package class, and draw the view according to the parameters of the package class (refer to the drawing method of sample code). Note that because the interface involves network requests, you need to open a child thread to call the interface.

// 获取ImageLayoutInfo返回值
new Thread(new Runnable() {
    @Override    
    public void run() {
            ImageLayoutInfo imageLayoutInfo = imageVisionAPI.analyzeImageLayout(requestJson, imageBitmap);
        }           
    }).start();

ImageLayoutInfo return value:

Insert picture description here

response field:

Insert picture description here

Note: When using the graphic intelligent typesetting service, the developer needs to ensure that the provided token is valid, otherwise the service cannot be used. For the method of obtaining token, please refer to the method of obtaining token: https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/get_token-0000001055139693-V5 .

Step 6: Stop the service.

When the graphic intelligent typesetting effect is no longer needed, call this interface to stop the service. When stopCode is 0, the execution is successful.

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

Demo exhibition

Teach you to easily integrate the graphic layout function of Huawei Image Kit

Github source code

Github source code:https://github.com/HMS-Core/hms-image-vision-java


Original link:https://developer.huawei.com/consumer/cn/forum/topic/0201404755216720220?fid=18

Author: Pepper

Guess you like

Origin blog.51cto.com/14772288/2554006