Skip to content

Commit

Permalink
修复 截图错误
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Aug 31, 2024
1 parent 8baca8d commit 649e66f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 63 deletions.
27 changes: 18 additions & 9 deletions Core.Window/ScreenCaptureByDx11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public class DisposableTool(Action busySetter) : IDisposable
public void Dispose() => busySetter.Invoke();
}

public (Queue<Bitmap>, Queue<Bitmap>) CaptureAllScreen()
public Stack<ScreenCaptureResult> CaptureAllScreen()
{
Queue<Bitmap> bitmaps = new();
Queue<Bitmap> mosaics = new();
var screenCaptureResults = new Stack<ScreenCaptureResult>();

unsafe
{
DXGI dxgi = new DXGI(new DefaultNativeContext("dxgi"));
Expand Down Expand Up @@ -192,9 +192,7 @@ public class DisposableTool(Action busySetter) : IDisposable
}

span = null;

bitmaps.Enqueue(writeableBitmap);


var process = GaussianBlur1.GaussianBlur(array, desc.DesktopCoordinates.Size.X,
desc.DesktopCoordinates.Size.Y, 4);
var writeableBitmap2 = new WriteableBitmap(
Expand All @@ -209,8 +207,19 @@ public class DisposableTool(Action busySetter) : IDisposable
desc.DesktopCoordinates.Size.X * 4);
}
}

mosaics.Enqueue(writeableBitmap2);

screenCaptureResults.Push(new ScreenCaptureResult()
{
Source = writeableBitmap,
Mosaic = writeableBitmap2,
Info = new ScreenCaptureInfo()
{
Height = desc.DesktopCoordinates.Size.Y,
Width = desc.DesktopCoordinates.Size.X,
X= desc.DesktopCoordinates.Min.X,
Y = desc.DesktopCoordinates.Min.Y
}
});
array = null;
process = null;

Expand Down Expand Up @@ -259,7 +268,7 @@ public class DisposableTool(Action busySetter) : IDisposable
}


return (bitmaps, mosaics);
return screenCaptureResults;
}

public (Bitmap?, Bitmap?)? CaptureScreen(ScreenCaptureInfo screenCaptureInfo, bool withMosaic = false)
Expand Down
83 changes: 31 additions & 52 deletions KitopiaAvalonia/Services/ScreenCaptureWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,25 @@ public class ScreenCaptureWindow : IScreenCaptureWindow
public void CaptureScreen()
{
var captureAllScreen = ServiceManager.Services.GetService<IScreenCapture>()!.CaptureAllScreen();
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
while (captureAllScreen.TryPop(out var result))
{
var screens = desktop.MainWindow.Screens;
for (var index = 0; index < screens.All.Count; index++)
var window = new Windows.ScreenCaptureWindow(0)
{
var screen = screens.All[index];
var rect = screen.Bounds;
new Windows.ScreenCaptureWindow(index)
{
Position = new PixelPoint(rect.X, rect.Y),
WindowState = WindowState.FullScreen,
SystemDecorations = SystemDecorations.None,
Background = new SolidColorBrush(Colors.Black),
ShowInTaskbar = false,
Topmost = true,
CanResize = false,
IsVisible = true,
MosaicImage =
{
Source = captureAllScreen.Item2.Count > 0 ? captureAllScreen.Item2.Dequeue() : null
},
Image =
{
Source = captureAllScreen.Item1.Count > 0 ? captureAllScreen.Item1.Dequeue() : null
}
}.Show();
}
}
Position = new PixelPoint(result.Info.X, result.Info.Y),
WindowState = WindowState.FullScreen,
SystemDecorations = SystemDecorations.None,
Background = new SolidColorBrush(Colors.Black),
ShowInTaskbar = false,
Topmost = false,
CanResize = false,
IsVisible = true,
};

captureAllScreen.Item2.Clear();
captureAllScreen.Item1.Clear();
window.MosaicImage.Source = result.Mosaic;
window.Image.Source = result.Source;
window.Show();
}

GC.Collect(2, GCCollectionMode.Aggressive);
}

Expand All @@ -64,35 +52,26 @@ public async Task<ScreenCaptureInfo> GetScreenCaptureInfo()
};
await semaphore.WaitAsync();
var captureAllScreen = ServiceManager.Services.GetService<IScreenCapture>()!.CaptureAllScreen();
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
while (captureAllScreen.TryPop(out var result))
{
var screens = desktop.MainWindow.Screens;
for (var index = 0; index < screens.All.Count; index++)
var window = new Windows.ScreenCaptureWindow(0)
{
var screen = screens.All[index];
var rect = screen.Bounds;
var window = new Windows.ScreenCaptureWindow(index)
{
Position = new PixelPoint(rect.X, rect.Y),
WindowState = WindowState.FullScreen,
SystemDecorations = SystemDecorations.None,
Background = new SolidColorBrush(Colors.Black),
ShowInTaskbar = false,
Topmost = false,
CanResize = false,
IsVisible = true,
};
Position = new PixelPoint(result.Info.X, result.Info.Y),
WindowState = WindowState.FullScreen,
SystemDecorations = SystemDecorations.None,
Background = new SolidColorBrush(Colors.Black),
ShowInTaskbar = false,
Topmost = false,
CanResize = false,
IsVisible = true,
};

window.MosaicImage.Source = captureAllScreen.Item2.Count > 0 ? captureAllScreen.Item2.Dequeue() : null;
window.Image.Source = captureAllScreen.Item1.Count > 0 ? captureAllScreen.Item1.Dequeue() : null;
window.SetToSelectMode(action);
window.Show();
}
window.MosaicImage.Source = result.Mosaic;
window.Image.Source = result.Source;
window.SetToSelectMode(action);
window.Show();
}

await semaphore.WaitAsync();
captureAllScreen.Item2.Clear();
captureAllScreen.Item1.Clear();
semaphore.Dispose();
GC.Collect(2, GCCollectionMode.Aggressive);

Expand Down
3 changes: 2 additions & 1 deletion KitopiaAvalonia/Windows/ScreenCaptureWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

<Canvas>

<Image Name="Image" />
<Image Name="Image" Width="{Binding $parent[Canvas].Bounds.Width}"
Height="{Binding $parent[Canvas].Bounds.Height}"/>
<Image Name="MosaicImage" Width="{Binding $parent[Canvas].Bounds.Width}"
Height="{Binding $parent[Canvas].Bounds.Height}">

Expand Down
2 changes: 1 addition & 1 deletion PluginCore
Submodule PluginCore updated 1 files
+7 −1 IScreenCapture.cs

0 comments on commit 649e66f

Please sign in to comment.