Step By Step
1.开通分割抠图服务。
分割抠图
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/278857e45dd24d3884b53baeaf8a84e1.png?x-oss-process=image/resize,w_1400/format,webp)
2.获取您的真实AK信息
查看AK
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/6e5812600ad44473bc43982cce7c8c60.png?x-oss-process=image/resize,w_1400/format,webp)
3.添加java依赖
<dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-imageseg</artifactId>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.13</version>
</dependency>
4.Java SDK Code
// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.imageseg20191230.*;
import com.aliyun.imageseg20191230.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.*;
import com.aliyun.teautil.models.*;
public class Sample {
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static com.aliyun.imageseg20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config()
// 您的 AccessKey ID
.setAccessKeyId(accessKeyId)
// 您的 AccessKey Secret
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "imageseg.cn-shanghai.aliyuncs.com";
return new com.aliyun.imageseg20191230.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.imageseg20191230.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
ChangeSkyRequest changeSkyRequest = new ChangeSkyRequest()
.setImageURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ChangeSky/ChangeSky2.jpg")
.setReplaceImageURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ChangeSky/ChangeSky6.jpg");
RuntimeOptions runtime = new RuntimeOptions();
try {
// 复制代码运行请自行打印 API 的返回值
client.changeSkyWithOptions(changeSkyRequest, runtime);
} catch (TeaException error) {
// 如有需要,请打印 error
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// 如有需要,请打印 error
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
5.运行结果图片
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/e57eb6f263204f97b32e736d703fdb81.png?x-oss-process=image/resize,w_1400/format,webp)