Table of Contents

Class ImageRedactor

Namespace
LMKit.Media.Image
Assembly
LM-Kit.NET.dll

Permanently covers content in raster images. Redacted regions are painted with a fully opaque fill directly into the pixel data, and the image is re-encoded, so the covered pixels cannot be recovered from the output file. Metadata blocks (EXIF, XMP, textual entries), which routinely duplicate content being redacted, are stripped by default.

public static class ImageRedactor
Inheritance
ImageRedactor
Inherited Members

Examples

Example 1: Redact every occurrence of a name.

using LMKit.Media.Image;

var request = new ImageRedactionRequest { OcrEngine = myOcrEngine }; request.SearchTerms.Add("John Doe");

ImageRedactionReport report = ImageRedactor.RedactToFile("scan.png", "scan_redacted.png", request); Console.WriteLine($"Matches: {report.SearchMatches}, areas painted: {report.FilledAreas}");

Example 2: Redact a fixed region in memory.

using LMKit.Media.Image;
using LMKit.Graphics.Geometry;

var request = new ImageRedactionRequest(); request.Areas.Add(new ImageRedactionArea(pageIndex: 0, Rectangle.FromSize(left: 72, top: 90, width: 220, height: 30)));

byte[] source = File.ReadAllBytes("badge.jpg"); ImageRedactionResult result = ImageRedactor.RedactToBytes(source, request); File.WriteAllBytes("badge_redacted.jpg", result.Data);

Remarks

Marking. An ImageRedactionRequest describes what to cover: explicit page areas in image pixels, and text search terms. Terms are located by reading the pixels through the request's OcrEngine, and every match is covered.

Multipage images. Every page of a multipage container is processed: areas apply to the page named by their PageIndex, and terms are searched on every page. Multipage output is encoded as multipage TIFF, the only multipage format the encoder produces.

Output format. The redacted image is re-encoded in the source format whenever an encoder for it exists (PNG, JPEG, WebP, BMP, TIFF, TGA, PNM). A source format without an encoder is re-encoded as PNG. OutputExtension always states what was produced.

Empty requests. A request carrying no areas and no terms is a no-op: the original bytes are returned untouched, without re-encoding or metadata stripping, with a zeroed report whose PagesProcessed still reflects the source page count.

Input modes. File paths, raw bytes and pre-built Attachment objects are accepted, each with RedactToFile and RedactToBytes variants in synchronous and asynchronous forms.

Methods

RedactToBytes(Attachment, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Redacts the image carried by attachment and returns the redacted bytes together with the report.

RedactToBytes(byte[], ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Redacts in-memory image bytes and returns the redacted bytes together with the report.

RedactToBytes(string, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Redacts the image at inputPath and returns the redacted bytes together with the report.

RedactToBytesAsync(Attachment, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Asynchronously redacts the image carried by attachment and returns the redacted bytes together with the report.

RedactToBytesAsync(byte[], ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Asynchronously redacts in-memory image bytes and returns the redacted bytes together with the report.

RedactToBytesAsync(string, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Asynchronously redacts the image at inputPath and returns the redacted bytes together with the report.

RedactToFile(Attachment, string, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Redacts the image carried by attachment and writes the result to outputPath.

RedactToFile(string, string, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Redacts the image at inputPath and writes the result to outputPath.

RedactToFileAsync(Attachment, string, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Asynchronously redacts the image carried by attachment and writes the result to outputPath.

RedactToFileAsync(string, string, ImageRedactionRequest, ImageRedactionOptions, CancellationToken)

Asynchronously redacts the image at inputPath and writes the result to outputPath.

Share