Revert ab29ec8: container==content auto-fit made it worse — back to alpha-crop with the container at element size

The container tracks the element's own Width/Height again; the crop stays in the bitmap.
This commit is contained in:
2026-08-28 12:09:13 -07:00
parent ab29ec801d
commit 9b56e88800
7 changed files with 51 additions and 103 deletions
+2 -11
View File
@@ -20,7 +20,7 @@ public sealed class WebView2Manager : IDisposable
private readonly Dispatcher _dispatcher;
private readonly Dictionary<string, WebSourceSession> _sessions = new();
public event Action<string, WriteableBitmap, double, double>? PreviewBitmapChanged;
public event Action<string, WriteableBitmap>? PreviewBitmapChanged;
private sealed class WebSourceSession
{
@@ -182,14 +182,6 @@ public sealed class WebView2Manager : IDisposable
return (minX, minY, maxX - minX + 1, maxY - minY + 1);
}
// The cropped pixel extent, expressed in MASTER CANVAS units (the WebView2 is
// 1920×1080 DIPs and captures at its physical size, so 1920/pixW maps capture
// pixels back to canvas units). The element grid + selection box are sized to
// this, so the container matches the content exactly instead of Fill-stretching
// a cropped bitmap into a larger frame.
internal static (double W, double H) ContentCanvasSize(int cropW, int cropH, int pixW, int pixH)
=> (cropW * (1920.0 / pixW), cropH * (1080.0 / pixH));
private async Task CaptureFrame(string sourceId)
{
if (!_sessions.TryGetValue(sourceId, out var session) || session.Disposed) return;
@@ -240,12 +232,11 @@ public sealed class WebView2Manager : IDisposable
wb.WritePixels(new Int32Rect(0, 0, cropW, cropH), outPixels, cropW * 4, 0);
wb.Freeze();
var (canvasW, canvasH) = ContentCanvasSize(cropW, cropH, pixW, pixH);
session.LatestFrame = new VideoFrame(cropW, cropH, outPixels);
_ = _dispatcher.BeginInvoke(() =>
{
PreviewBitmapChanged?.Invoke(sourceId, wb, canvasW, canvasH);
PreviewBitmapChanged?.Invoke(sourceId, wb);
});
}
catch (ObjectDisposedException) { }