[Huawei Developers] Freemind R:
Overview

HUAWEI Image Kit's smart layout service currently offers nine different smart layout styles, and two content layout types, which users are free to choose from.

Application Scenarios

When typesetting is performed for a digital magazine, for instance, many elements need to be incorporated onto the page, along with the text. Image Kit's smart layout service enables you to typeset with remarkable ease, and craft vivid designs, to enjoy greatly enhanced efficiency with eye-catching imagery that attracts users.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201119121437.56351604082482609387738115485928:50511123020149:2800:03C55F882292D54C9038BBFE45F2FA2E8EDA84D727640A476DB3D13C42CB901E.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201119121437.56351604082482609387738115485928:50511123020149:2800:03C55F882292D54C9038BBFE45F2FA2E8EDA84D727640A476DB3D13C42CB901E.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201119121437.13643739108977307151416003231077:50511123020149:2800:35CDF135F89FD9043F7ABF50C19A2A07E3DA85901B77B76C90B93E04B9152B0F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201119121437.13643739108977307151416003231077:50511123020149:2800:35CDF135F89FD9043F7ABF50C19A2A07E3DA85901B77B76C90B93E04B9152B0F.png[/IMG]

Development Practice

Now, let's take a look at how to integrate Image Kit's smart layout service.

Preparations

You'll need to add your images and configure related parameters during this process.

1. Import the smart layout service packages.

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

2. Obtain an instance for the smart layout service.

// Obtain an ImageVisionImpl instance.
ImageVisionImpl imageVisionAPI = ImageVision.getInstance(this);

3. Initialize the service, which is the same as that for the filter service. For details, please refer to Development Procedure.

4. Construct parameter objects.

More detail about this, please check https://forums.developer.huawei.com/forumPortal/en/topic/0204411709476790211

For details about authJson parameters, please refer to Description of authJson parameters

Example requestJson parameter configuration:

{
"requestId":"requestId",
"taskJson":{"title":"Little luxury for the new gen","description":"Away from hustle and bustle","copyRight":"HUAWEIScreenMagazine","isNeedMask":false,"anchor":"More","styleList":["info1"]}, "authJson":{"projectId":"projectIdTest","appId":"appIdTest","authApiKey":"authApiKeyTest","clientSecret":"CSecretTest","clientId":"CIdTest","token":"tokenTest"}
}

5. Obtain the service result.

When calling the smart layout API, you'll need to specify the bitmap of the image to be processed, and select the style and text to be added (parameters). For details, please refer to step 4. The smart layout service requires a network connection. If no network connection is available, the info3 style is returned by default. The layout style is returned through ImageLayoutInfo. The smart layout service draws a view based on the style contained in ImageLayoutInfo. For more detailed operations, please refer to Sample Code. Because network requests are sent over the API, you'll need to call the API in a subthread.

//Obtain the return result from ImageLayoutInfo.
new Thread(new Runnable() {
@Override
public void run() {
ImageLayoutInfo imageLayoutInfo = imageVisionAPI.analyzeImageLayout(requestJson, imageBitmap);
}
}).start();

6. Stop the service.

If you do not need to use smart layout any longer, call the imageVisionAPI.stop() API to stop the service. If the returned stopCode is 0, it means that the service has been successfully stopped.

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

Source Code

To download the source code, please visit GitHub.