Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit eb5141e

Browse files
authored
Fix Window ScreenShot (#314)
- Removed ScreenShot Transforms in favour of Image Editor Corresponding Settings, Localisations and UI removed. - Fix Window Rectangle finding code. - New option in ScreenShot settings: `Window ScreenShot Transparency` to specify whether window screenshots should be transparent. - Mouse Cursor included in Window ScreenShot only if within window bounds. - Capture Window Transparent region inflation reduced from 100px to 20px. - Refactor code into a `WindowScreenShotBackdrop` class. - Other Fixes: - `CustomSize` used instead of `CustomUrl` on `FFmpegPage` - `MouseRightClickColor` used instead of `MouseMiddleClickColor` on `MouseOverlayPage`
1 parent 14f2d3d commit eb5141e

File tree

15 files changed

+141
-321
lines changed

15 files changed

+141
-321
lines changed

src/Captura.Core/Captura.Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
<Compile Include="Models\Overlays\WebcamOverlay.cs" />
9292
<Compile Include="Models\Recents\RecentFileType.cs" />
9393
<Compile Include="Models\RecorderState.cs" />
94-
<Compile Include="Models\RotateBy.cs" />
9594
<Compile Include="Settings\Models\WebcamOverlaySettings.cs" />
9695
<Compile Include="Models\FileContentItem.cs" />
9796
<Compile Include="ViewModels\CrashLogsViewModel.cs" />

src/Captura.Core/Extensions.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,6 @@ static Bitmap Resize(this Bitmap Image, Size Resize, bool KeepAspectRatio, bool
5353
return resized;
5454
}
5555

56-
public static Bitmap Transform(this Bitmap Image, ScreenShotSettings TransformSettings, bool SkipResize = false)
57-
{
58-
if (TransformSettings.Resize && !SkipResize)
59-
{
60-
Image = Image.Resize(new Size(TransformSettings.ResizeWidth, TransformSettings.ResizeHeight), true);
61-
}
62-
63-
#region Rotate Flip
64-
var flip = "Flip";
65-
66-
if (!TransformSettings.FlipHorizontal && !TransformSettings.FlipVertical)
67-
flip += "None";
68-
69-
if (TransformSettings.FlipHorizontal)
70-
flip += "X";
71-
72-
if (TransformSettings.FlipVertical)
73-
flip += "Y";
74-
75-
var rotateFlip = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), TransformSettings.RotateBy + flip);
76-
77-
Image.RotateFlip(rotateFlip);
78-
#endregion
79-
80-
return Image;
81-
}
82-
8356
public static async Task UploadToImgur(this Bitmap Bitmap)
8457
{
8558
var imgur = ServiceProvider.Get<ImgurWriter>();

src/Captura.Core/Models/RotateBy.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,7 @@
1-
using Captura.Models;
2-
3-
namespace Captura
1+
namespace Captura
42
{
53
public class ScreenShotSettings : PropertyStore
64
{
7-
public bool Resize
8-
{
9-
get => Get<bool>();
10-
set => Set(value);
11-
}
12-
13-
public int ResizeWidth
14-
{
15-
get => Get(640);
16-
set => Set(value);
17-
}
18-
19-
public int ResizeHeight
20-
{
21-
get => Get(400);
22-
set => Set(value);
23-
}
24-
25-
public bool FlipHorizontal
26-
{
27-
get => Get<bool>();
28-
set => Set(value);
29-
}
30-
31-
public bool FlipVertical
32-
{
33-
get => Get<bool>();
34-
set => Set(value);
35-
}
36-
37-
public RotateBy RotateBy
38-
{
39-
get => Get<RotateBy>();
40-
set => Set(value);
41-
}
42-
435
public string ImageFormat
446
{
457
get => Get("Png");
@@ -51,5 +13,11 @@ public string[] SaveTargets
5113
get => Get(new []{ "Disk" });
5214
set => Set(value);
5315
}
16+
17+
public bool WindowShotTransparent
18+
{
19+
get => Get(true);
20+
set => Set(value);
21+
}
5422
}
5523
}

src/Captura.Core/ViewModels/ScreenShotViewModel.cs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -132,35 +132,31 @@ public async Task SaveScreenShot(Bitmap Bmp, string FileName = null)
132132
else _systemTray.ShowNotification(new TextNotification(Loc.ImgEmpty));
133133
}
134134

135-
public Bitmap ScreenShotWindow(IWindow hWnd)
135+
public Bitmap ScreenShotWindow(IWindow Window)
136136
{
137137
_systemTray.HideNotification();
138138

139-
if (hWnd.Handle == Window.DesktopWindow.Handle)
139+
if (Window.Handle == Screna.Window.DesktopWindow.Handle)
140140
{
141-
return ScreenShot.Capture(Settings.IncludeCursor).Transform(Settings.ScreenShots);
141+
return ScreenShot.Capture(Settings.IncludeCursor);
142142
}
143143

144-
var bmp = ScreenShot.CaptureTransparent(hWnd,
145-
Settings.IncludeCursor,
146-
Settings.ScreenShots.Resize,
147-
Settings.ScreenShots.ResizeWidth,
148-
Settings.ScreenShots.ResizeHeight);
149-
150-
// Capture without Transparency
151-
if (bmp == null)
144+
try
152145
{
153-
try
154-
{
155-
return ScreenShot.Capture(hWnd, Settings.IncludeCursor)?.Transform(Settings.ScreenShots);
156-
}
157-
catch
146+
Bitmap bmp = null;
147+
148+
if (Settings.ScreenShots.WindowShotTransparent)
158149
{
159-
return null;
150+
bmp = ScreenShot.CaptureTransparent(Window, Settings.IncludeCursor);
160151
}
161-
}
162152

163-
return bmp.Transform(Settings.ScreenShots, true);
153+
// Capture without Transparency
154+
return bmp ?? ScreenShot.Capture(Window, Settings.IncludeCursor);
155+
}
156+
catch
157+
{
158+
return null;
159+
}
164160
}
165161

166162
public async void CaptureScreenShot(string FileName = null)
@@ -221,13 +217,10 @@ public async Task<Bitmap> GetScreenShot()
221217
case ScreenSourceProvider _:
222218
if (selectedVideoSource is ScreenItem screen)
223219
bmp = screen.Capture(includeCursor);
224-
225-
bmp = bmp?.Transform(Settings.ScreenShots);
226220
break;
227221

228222
case RegionSourceProvider _:
229223
bmp = ScreenShot.Capture(_regionProvider.SelectedRegion, includeCursor);
230-
bmp = bmp.Transform(Settings.ScreenShots);
231224
break;
232225
}
233226

@@ -262,13 +255,5 @@ public ImageFormat SelectedScreenShotImageFormat
262255
OnPropertyChanged();
263256
}
264257
}
265-
266-
public IEnumerable<KeyValuePair<RotateBy, string>> Rotations { get; } = new[]
267-
{
268-
new KeyValuePair<RotateBy, string>(RotateBy.RotateNone, "No Rotation"),
269-
new KeyValuePair<RotateBy, string>(RotateBy.Rotate90, "90° Clockwise"),
270-
new KeyValuePair<RotateBy, string>(RotateBy.Rotate180, "180° Clockwise"),
271-
new KeyValuePair<RotateBy, string>(RotateBy.Rotate270, "90° Anticlockwise")
272-
};
273258
}
274259
}

src/Captura.Loc/LanguageFields.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,6 @@ public string FileNaming
301301
set => Set(value);
302302
}
303303

304-
public string Flip
305-
{
306-
get => Get();
307-
set => Set(value);
308-
}
309-
310304
public string FontSize
311305
{
312306
get => Get();
@@ -331,12 +325,6 @@ public string HideOnFullScreenShot
331325
set => Set(value);
332326
}
333327

334-
public string Horizontal
335-
{
336-
get => Get();
337-
set => Set(value);
338-
}
339-
340328
public string Host
341329
{
342330
get => Get();
@@ -745,12 +733,6 @@ public string Right
745733
set => Set(value);
746734
}
747735

748-
public string Rotate
749-
{
750-
get => Get();
751-
set => Set(value);
752-
}
753-
754736
public string SaveToClipboard
755737
{
756738
get => Get();
@@ -787,12 +769,6 @@ public string ScreenShotSaved
787769
set => Set(value);
788770
}
789771

790-
public string ScreenShotTransforms
791-
{
792-
get => Get();
793-
set => Set(value);
794-
}
795-
796772
public string SelectFFmpegFolder
797773
{
798774
get => Get();
@@ -913,12 +889,6 @@ public string VarFrameRate
913889
set => Set(value);
914890
}
915891

916-
public string Vertical
917-
{
918-
get => Get();
919-
set => Set(value);
920-
}
921-
922892
public string Video
923893
{
924894
get => Get();
@@ -997,6 +967,12 @@ public string Window
997967
set => Set(value);
998968
}
999969

970+
public string WindowScreenShotTransparency
971+
{
972+
get => Get();
973+
set => Set(value);
974+
}
975+
1000976
public string Yes
1001977
{
1002978
get => Get();

src/Captura.Loc/Languages/en.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@
4545
"FileMenuOpen": "Open",
4646
"FileMenuSave": "Save",
4747
"FileNaming": "File Naming",
48-
"Flip": "Flip",
4948
"FontSize": "Font Size",
5049
"FrameRate": "FPS",
5150
"FullScreen": "Full Screen",
5251
"HideOnFullScreenShot": "Hide on Full Screen ScreenShot",
53-
"Horizontal": "Horizontal",
5452
"Host": "Host",
5553
"Hotkeys": "Hotkeys",
5654
"ImageEditor": "Image Editor",
@@ -119,14 +117,12 @@
119117
"Resize": "Resize",
120118
"RestoreDefaults": "Restore Defaults",
121119
"Right": "Right",
122-
"Rotate": "Rotate",
123120
"SaveToClipboard": "Save to Clipboard",
124121
"Screen": "Screen",
125122
"ScreenShot": "ScreenShot",
126123
"ScreenShotActiveWindow": "ScreenShot Active Window",
127124
"ScreenShotDesktop": "ScreenShot Desktop",
128125
"ScreenShotSaved": "ScreenShot Saved",
129-
"ScreenShotTransforms": "ScreenShot Transforms",
130126
"SelectFFmpegFolder": "Select FFmpeg Folder",
131127
"SelectOutFolder": "Select Output Folder",
132128
"SeparateAudioFiles": "Separate files for every audio source",
@@ -147,7 +143,6 @@
147143
"UseProxyAuth": "Use Proxy Authentication",
148144
"UserName": "User Name",
149145
"VarFrameRate": "Variable Frame Rate",
150-
"Vertical": "Vertical",
151146
"Video": "Video",
152147
"VideoEncoder": "Video Encoder",
153148
"VideoSaved": "Video Saved",
@@ -161,5 +156,6 @@
161156
"WebCamView": "WebCam View",
162157
"Website": "Website",
163158
"Window": "Window",
159+
"WindowScreenShotTransparency": "Window ScreenShot Transparency",
164160
"Yes": "Yes"
165161
}

src/Captura/Pages/FFmpegPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
Stretch="Uniform"
166166
HorizontalAlignment="Center"
167167
VerticalAlignment="Center"/>
168-
<Label Content="{Binding CustomSize, Source={StaticResource Loc}, Mode=OneWay}"
168+
<Label Content="{Binding CustomUrl, Source={StaticResource Loc}, Mode=OneWay}"
169169
Grid.Column="1"
170170
Grid.Row="2"
171171
ContentStringFormat="{}{0}:"/>

src/Captura/Pages/MouseOverlayPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
Grid.Column="1"
121121
Margin="0,5"/>
122122

123-
<Label Content="{Binding MouseRightClickColor, Source={StaticResource Loc}, Mode=OneWay}"
123+
<Label Content="{Binding MouseMiddleClickColor, Source={StaticResource Loc}, Mode=OneWay}"
124124
ContentStringFormat="{}{0}: "
125125
Margin="0,5,5,5"
126126
Grid.Row="3"/>

0 commit comments

Comments
 (0)