/// <summary> /// Crop an existing image, and upload updated image to Cloud Storage. /// </summary> public void CropImageAndUploadToStorage() { Console.WriteLine("Crops the image and upload to cloud storage"); UploadSampleImageToCloud(); // Please refer to https://docs.aspose.cloud/display/imagingcloud/Supported+File+Formats#SupportedFileFormats-Crop // for possible output formats var format = "jpg"; // Resulting image format. int? x = 10; int? y = 10; int? width = 100; int? height = 150; var folder = CloudPath; // Input file is saved at the Examples folder in the storage string storage = null; // We are using default Cloud Storage var request = new CropImageRequest(SampleImageFileName, x, y, width, height, format, folder, storage); Console.WriteLine($"Call CropImage with params:x:{x},y:{y}, width:{width}, height:{height}"); using (var updatedImage = ImagingApi.CropImage(request)) { UploadImageToCloud(GetModifiedSampleImageFileName(false, format), updatedImage); } Console.WriteLine(); }
public void CropImageTest(string formatExtension, params string[] additionalExportFormats) { string name = null; int? x = 10; int? y = 10; int? width = 100; int? height = 150; string folder = TempFolder; string storage = this.TestStorage; List <string> formatsToExport = new List <string>(this.BasicExportFormats); foreach (string additionalExportFormat in additionalExportFormats) { if (!formatsToExport.Contains(additionalExportFormat)) { formatsToExport.Add(additionalExportFormat); } } foreach (StorageFile inputFile in BasicInputTestFiles) { if (inputFile.Name.EndsWith(formatExtension)) { name = inputFile.Name; } else { continue; } foreach (string format in formatsToExport) { this.TestGetRequest( "CropImageTest", $"Input image: {name}; Output format: {format ?? "null"}; Width: {width}; Height: {height}; X: {x}; Y: {y}", name, delegate { var request = new CropImageRequest(name, x, y, width, height, format, folder, storage); return(ImagingApi.CropImage(request)); }, delegate(ImagingResponse originalProperties, ImagingResponse resultProperties, Stream resultStream) { Assert.AreEqual(width, resultProperties.Width); Assert.AreEqual(height, resultProperties.Height); }, folder, storage); } } }
/// <summary> /// 根据输入的裁剪比例,智能判断一张图片的最佳裁剪区域,确保原图的主体区域不受影响。 /// /// 可以自动裁剪图片,适应不同平台、设备的展示要求,避免简单拉伸带来的变形。 /// > /// - 公共参数中的签名方式必须指定为V3版本,即配置SignatureMethod参数为TC3-HMAC-SHA256。 /// </summary> /// <param name="req"><see cref="CropImageRequest"/></param> /// <returns><see cref="CropImageResponse"/></returns> public CropImageResponse CropImageSync(CropImageRequest req) { JsonResponseModel <CropImageResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "CropImage"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <CropImageResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }