Refactor ComposeSignaturePreviewPng to return Stream

Updated the `ComposeSignaturePreviewPng` method in the `IPdfPageImageRenderer` interface to return a `Stream` instead of a `byte[]` for improved memory efficiency when handling large image data.

- Added `ComposeSignaturePreviewPngBytes` extension method to convert the `Stream` to a `byte[]` for backward compatibility.
- Updated `PdfPageImageRenderer` to return a `Stream` and adjusted its internal logic to reset the `MemoryStream` position before returning.
- Modified `DevSignatureInkController` to use the `Stream`-based implementation for HTTP responses.
- Made minor formatting adjustments in `PdfPageImageRenderer`.

These changes optimize memory usage while maintaining compatibility with existing workflows that require `byte[]`.
This commit is contained in:
2026-10-19 14:49:48 +02:00
parent 31bf64a6f2
commit f1c8e223dd
3 changed files with 21 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ public interface IPdfPageImageRenderer
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
byte[] ComposeSignaturePreviewPng(ISignatureInkPayload element);
Stream ComposeSignaturePreviewPng(ISignatureInkPayload element);
/// <summary>
///
@@ -51,4 +51,16 @@ public static class PdfPageImageRendererExtensions
return inkBytes;
}
}
public static byte[] ComposeSignaturePreviewPngBytes(this IPdfPageImageRenderer renderer, ISignatureInkPayload element)
{
using var stream = renderer.ComposeSignaturePreviewPng(element);
if (stream is MemoryStream memoryStream)
return memoryStream.ToArray();
using var copy = new MemoryStream();
stream.CopyTo(copy);
return copy.ToArray();
}
}