简介
SDK API 参考
缩放
示例代码
String bucket = "examplebucket-1250000000"; //存储桶名称,格式:BucketName-APPIDString cosPath = "exampleobject"; //对象位于存储桶中的位置标识符,即对象键String savePath = context.getExternalCacheDir().toString(); //本地路径GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, cosPath,savePath);getObjectRequest.addQuery("imageMogr2/thumbnail/!50p", null);cosXmlService.getObjectAsync(getObjectRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest cosXmlRequest,CosXmlResult cosXmlResult) {GetObjectResult getObjectResult = (GetObjectResult) cosXmlResult;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
说明
裁剪
下面示例展示了如何对已存储在 COS 的图片进行相应处理操作,并将结果存入到 COS。
示例代码
String bucket = "examplebucket-1250000000"; //存储桶名称,格式:BucketName-APPIDString cosPath = "exampleobject"; //对象位于存储桶中的位置标识符,即对象键String savePath = context.getExternalCacheDir().toString(); //本地路径GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, cosPath,savePath);getObjectRequest.addQuery("imageMogr2/iradius/150", null);cosXmlService.getObjectAsync(getObjectRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest cosXmlRequest,CosXmlResult cosXmlResult) {GetObjectResult getObjectResult = (GetObjectResult) cosXmlResult;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
说明
旋转
下面示例展示了如何对已存储在 COS 的图片在下载时进行处理操作。
示例代码
String bucket = "examplebucket-1250000000"; //存储桶名称,格式:BucketName-APPIDString cosPath = "exampleobject"; //对象位于存储桶中的位置标识符,即对象键String savePath = context.getExternalCacheDir().toString(); //本地路径GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, cosPath,savePath);getObjectRequest.addQuery("imageMogr2/rotate/90", null);cosXmlService.getObjectAsync(getObjectRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest cosXmlRequest,CosXmlResult cosXmlResult) {GetObjectResult getObjectResult = (GetObjectResult) cosXmlResult;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
说明