Android one-key cutout, cutout portrait

Android one-click cutout, cutout portrait, super simple, the only disadvantage is that it costs money

# 1, three-party development platform, you need to register Zuotang and buy a key

```

https://picwish.cn/background-removal-api-doc#/

```

# 2, postman interface test:

https://techsz.aoscdn.com/api/tasks/visual/segmentation

Request Headers:

```

"X-API-KEY": "This is the key that you bought for money, there is a free one that can be used several times"

```

Request Body:

```

{

"image_base64": "Image base64 string, be careful not to add a prefix",

"sync": 1, // This is a synchronous and asynchronous selection of int type, fill in 1 to return the result synchronously

"type":"person"

}

```

The request returns successfully:

```

{

"status": 200,

"data": {

"completed_at": 1679038527,

"created_at": 1679038527,

"download_time": 14,

"err_info": "",

"foreground_rect": {

"x": 0,

"y": 0,

"width": 1080,

"height": 1066

},

"image": "https://wxtechsz.oss-cn-shenzhen.aliyuncs.com/tasks/output/segmentation/816dd719-89e0-437a-8c3c-3eb40983dae2-image.png?Expires=1679042128&OSSAccessKeyId=LTAI5tGjJnh66c1txANiRBQN&Signature=fxU%2BIGzkwbdVF04%2Bn69j3iWM0fw%3D",

"output_type": 2,

"processed_at": 1679038527,

"progress": 100,

"result_type": "person",

"return_type": 1,

"state": 1,

"task_id": "816dd719-89e0-437a-8c3c-3eb40983dae2",

"time_elapsed": 413.06,

"type": "person"

}

}

```

# Directly select the synchronous request

```

OkHttpClient okHttpClient = new OkHttpClient.Builder().build();

RequestBody requestBody = new MultipartBody.Builder()

.setType(MultipartBody.FORM)

.addFormDataPart("image_file", {YOUR_JPG_PATH}, RequestBody.create({JPG_FILE}, MediaType.parse("image/jpeg")))

.addFormDataPart("sync", 1)

.build();

Request request = new Request.Builder()

.url("https://techsz.aoscdn.com/api/tasks/visual/segmentation")

.addHeader("X-API-KEY", "{YOUR_API_KEY}")

.post(requestBody)

.build();

Response response = okHttpClient.newCall(request).execute();

```

As an IT cow and horse, brothers and sisters are welcome to leave a message, which is the greatest encouragement to me

Guess you like

Origin blog.csdn.net/jun_tong/article/details/129622684