/// <summary>Snippet for RedactImage</summary> public void RedactImage_RequestObject() { // Snippet: RedactImage(RedactImageRequest,CallSettings) // Create client DlpServiceClient dlpServiceClient = DlpServiceClient.Create(); // Initialize request argument(s) RedactImageRequest request = new RedactImageRequest { ParentAsProjectName = new ProjectName("[PROJECT]"), }; // Make the request RedactImageResponse response = dlpServiceClient.RedactImage(request); // End snippet }
/// <summary>Snippet for RedactImageAsync</summary> public async Task RedactImageAsync_RequestObject() { // Snippet: RedactImageAsync(RedactImageRequest,CallSettings) // Additional: RedactImageAsync(RedactImageRequest,CancellationToken) // Create client DlpServiceClient dlpServiceClient = await DlpServiceClient.CreateAsync(); // Initialize request argument(s) RedactImageRequest request = new RedactImageRequest { ParentAsProjectName = new ProjectName("[PROJECT]"), }; // Make the request RedactImageResponse response = await dlpServiceClient.RedactImageAsync(request); // End snippet }
public async Task RedactImageAsync() { Mock <DlpService.DlpServiceClient> mockGrpcClient = new Mock <DlpService.DlpServiceClient>(MockBehavior.Strict); RedactImageRequest request = new RedactImageRequest { ParentAsProjectName = new ProjectName("[PROJECT]"), }; RedactImageResponse expectedResponse = new RedactImageResponse { RedactedImage = ByteString.CopyFromUtf8("28"), ExtractedText = "extractedText998260012", }; mockGrpcClient.Setup(x => x.RedactImageAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <RedactImageResponse>(Task.FromResult(expectedResponse), null, null, null, null)); DlpServiceClient client = new DlpServiceClientImpl(mockGrpcClient.Object, null); RedactImageResponse response = await client.RedactImageAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
// [START redact_image] public static object RedactFromImage(string projectId, string originalImagePath, string redactedImagePath) { var request = new RedactImageRequest { ParentAsProjectName = new ProjectName(projectId), InspectConfig = new InspectConfig { MinLikelihood = Likelihood.Likely, Limits = new InspectConfig.Types.FindingLimits() { MaxFindingsPerItem = 5 }, IncludeQuote = true, InfoTypes = { new InfoType { Name = "PHONE_NUMBER" }, new InfoType { Name = "EMAIL_ADDRESS" } } }, ByteItem = new ByteContentItem { Type = ByteContentItem.Types.BytesType.ImagePng, Data = ByteString.FromStream(new FileStream(originalImagePath, FileMode.Open)) }, }; var client = DlpServiceClient.Create(); var response = client.RedactImage(request); Console.WriteLine($"Extracted text: {response.ExtractedText}"); // Writes redacted image into file response.RedactedImage.WriteTo(new FileStream(redactedImagePath, FileMode.Create, FileAccess.Write)); return(0); }