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

Commit

Permalink
Fix Window ScreenShot (#314)
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
MathewSachin authored Nov 9, 2018
1 parent 14f2d3d commit eb5141e
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 321 deletions.
1 change: 0 additions & 1 deletion src/Captura.Core/Captura.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
<Compile Include="Models\Overlays\WebcamOverlay.cs" />
<Compile Include="Models\Recents\RecentFileType.cs" />
<Compile Include="Models\RecorderState.cs" />
<Compile Include="Models\RotateBy.cs" />
<Compile Include="Settings\Models\WebcamOverlaySettings.cs" />
<Compile Include="Models\FileContentItem.cs" />
<Compile Include="ViewModels\CrashLogsViewModel.cs" />
Expand Down
27 changes: 0 additions & 27 deletions src/Captura.Core/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,6 @@ static Bitmap Resize(this Bitmap Image, Size Resize, bool KeepAspectRatio, bool
return resized;
}

public static Bitmap Transform(this Bitmap Image, ScreenShotSettings TransformSettings, bool SkipResize = false)
{
if (TransformSettings.Resize && !SkipResize)
{
Image = Image.Resize(new Size(TransformSettings.ResizeWidth, TransformSettings.ResizeHeight), true);
}

#region Rotate Flip
var flip = "Flip";

if (!TransformSettings.FlipHorizontal && !TransformSettings.FlipVertical)
flip += "None";

if (TransformSettings.FlipHorizontal)
flip += "X";

if (TransformSettings.FlipVertical)
flip += "Y";

var rotateFlip = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), TransformSettings.RotateBy + flip);

Image.RotateFlip(rotateFlip);
#endregion

return Image;
}

public static async Task UploadToImgur(this Bitmap Bitmap)
{
var imgur = ServiceProvider.Get<ImgurWriter>();
Expand Down
10 changes: 0 additions & 10 deletions src/Captura.Core/Models/RotateBy.cs

This file was deleted.

46 changes: 7 additions & 39 deletions src/Captura.Core/Settings/Models/ScreenShotSettings.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
using Captura.Models;

namespace Captura
namespace Captura
{
public class ScreenShotSettings : PropertyStore
{
public bool Resize
{
get => Get<bool>();
set => Set(value);
}

public int ResizeWidth
{
get => Get(640);
set => Set(value);
}

public int ResizeHeight
{
get => Get(400);
set => Set(value);
}

public bool FlipHorizontal
{
get => Get<bool>();
set => Set(value);
}

public bool FlipVertical
{
get => Get<bool>();
set => Set(value);
}

public RotateBy RotateBy
{
get => Get<RotateBy>();
set => Set(value);
}

public string ImageFormat
{
get => Get("Png");
Expand All @@ -51,5 +13,11 @@ public string[] SaveTargets
get => Get(new []{ "Disk" });
set => Set(value);
}

public bool WindowShotTransparent
{
get => Get(true);
set => Set(value);
}
}
}
45 changes: 15 additions & 30 deletions src/Captura.Core/ViewModels/ScreenShotViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,31 @@ public async Task SaveScreenShot(Bitmap Bmp, string FileName = null)
else _systemTray.ShowNotification(new TextNotification(Loc.ImgEmpty));
}

public Bitmap ScreenShotWindow(IWindow hWnd)
public Bitmap ScreenShotWindow(IWindow Window)
{
_systemTray.HideNotification();

if (hWnd.Handle == Window.DesktopWindow.Handle)
if (Window.Handle == Screna.Window.DesktopWindow.Handle)
{
return ScreenShot.Capture(Settings.IncludeCursor).Transform(Settings.ScreenShots);
return ScreenShot.Capture(Settings.IncludeCursor);
}

var bmp = ScreenShot.CaptureTransparent(hWnd,
Settings.IncludeCursor,
Settings.ScreenShots.Resize,
Settings.ScreenShots.ResizeWidth,
Settings.ScreenShots.ResizeHeight);

// Capture without Transparency
if (bmp == null)
try
{
try
{
return ScreenShot.Capture(hWnd, Settings.IncludeCursor)?.Transform(Settings.ScreenShots);
}
catch
Bitmap bmp = null;

if (Settings.ScreenShots.WindowShotTransparent)
{
return null;
bmp = ScreenShot.CaptureTransparent(Window, Settings.IncludeCursor);
}
}

return bmp.Transform(Settings.ScreenShots, true);
// Capture without Transparency
return bmp ?? ScreenShot.Capture(Window, Settings.IncludeCursor);
}
catch
{
return null;
}
}

public async void CaptureScreenShot(string FileName = null)
Expand Down Expand Up @@ -221,13 +217,10 @@ public async Task<Bitmap> GetScreenShot()
case ScreenSourceProvider _:
if (selectedVideoSource is ScreenItem screen)
bmp = screen.Capture(includeCursor);

bmp = bmp?.Transform(Settings.ScreenShots);
break;

case RegionSourceProvider _:
bmp = ScreenShot.Capture(_regionProvider.SelectedRegion, includeCursor);
bmp = bmp.Transform(Settings.ScreenShots);
break;
}

Expand Down Expand Up @@ -262,13 +255,5 @@ public ImageFormat SelectedScreenShotImageFormat
OnPropertyChanged();
}
}

public IEnumerable<KeyValuePair<RotateBy, string>> Rotations { get; } = new[]
{
new KeyValuePair<RotateBy, string>(RotateBy.RotateNone, "No Rotation"),
new KeyValuePair<RotateBy, string>(RotateBy.Rotate90, "90° Clockwise"),
new KeyValuePair<RotateBy, string>(RotateBy.Rotate180, "180° Clockwise"),
new KeyValuePair<RotateBy, string>(RotateBy.Rotate270, "90° Anticlockwise")
};
}
}
36 changes: 6 additions & 30 deletions src/Captura.Loc/LanguageFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,6 @@ public string FileNaming
set => Set(value);
}

public string Flip
{
get => Get();
set => Set(value);
}

public string FontSize
{
get => Get();
Expand All @@ -331,12 +325,6 @@ public string HideOnFullScreenShot
set => Set(value);
}

public string Horizontal
{
get => Get();
set => Set(value);
}

public string Host
{
get => Get();
Expand Down Expand Up @@ -745,12 +733,6 @@ public string Right
set => Set(value);
}

public string Rotate
{
get => Get();
set => Set(value);
}

public string SaveToClipboard
{
get => Get();
Expand Down Expand Up @@ -787,12 +769,6 @@ public string ScreenShotSaved
set => Set(value);
}

public string ScreenShotTransforms
{
get => Get();
set => Set(value);
}

public string SelectFFmpegFolder
{
get => Get();
Expand Down Expand Up @@ -913,12 +889,6 @@ public string VarFrameRate
set => Set(value);
}

public string Vertical
{
get => Get();
set => Set(value);
}

public string Video
{
get => Get();
Expand Down Expand Up @@ -997,6 +967,12 @@ public string Window
set => Set(value);
}

public string WindowScreenShotTransparency
{
get => Get();
set => Set(value);
}

public string Yes
{
get => Get();
Expand Down
6 changes: 1 addition & 5 deletions src/Captura.Loc/Languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@
"FileMenuOpen": "Open",
"FileMenuSave": "Save",
"FileNaming": "File Naming",
"Flip": "Flip",
"FontSize": "Font Size",
"FrameRate": "FPS",
"FullScreen": "Full Screen",
"HideOnFullScreenShot": "Hide on Full Screen ScreenShot",
"Horizontal": "Horizontal",
"Host": "Host",
"Hotkeys": "Hotkeys",
"ImageEditor": "Image Editor",
Expand Down Expand Up @@ -119,14 +117,12 @@
"Resize": "Resize",
"RestoreDefaults": "Restore Defaults",
"Right": "Right",
"Rotate": "Rotate",
"SaveToClipboard": "Save to Clipboard",
"Screen": "Screen",
"ScreenShot": "ScreenShot",
"ScreenShotActiveWindow": "ScreenShot Active Window",
"ScreenShotDesktop": "ScreenShot Desktop",
"ScreenShotSaved": "ScreenShot Saved",
"ScreenShotTransforms": "ScreenShot Transforms",
"SelectFFmpegFolder": "Select FFmpeg Folder",
"SelectOutFolder": "Select Output Folder",
"SeparateAudioFiles": "Separate files for every audio source",
Expand All @@ -147,7 +143,6 @@
"UseProxyAuth": "Use Proxy Authentication",
"UserName": "User Name",
"VarFrameRate": "Variable Frame Rate",
"Vertical": "Vertical",
"Video": "Video",
"VideoEncoder": "Video Encoder",
"VideoSaved": "Video Saved",
Expand All @@ -161,5 +156,6 @@
"WebCamView": "WebCam View",
"Website": "Website",
"Window": "Window",
"WindowScreenShotTransparency": "Window ScreenShot Transparency",
"Yes": "Yes"
}
2 changes: 1 addition & 1 deletion src/Captura/Pages/FFmpegPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
Stretch="Uniform"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Label Content="{Binding CustomSize, Source={StaticResource Loc}, Mode=OneWay}"
<Label Content="{Binding CustomUrl, Source={StaticResource Loc}, Mode=OneWay}"
Grid.Column="1"
Grid.Row="2"
ContentStringFormat="{}{0}:"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Captura/Pages/MouseOverlayPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
Grid.Column="1"
Margin="0,5"/>

<Label Content="{Binding MouseRightClickColor, Source={StaticResource Loc}, Mode=OneWay}"
<Label Content="{Binding MouseMiddleClickColor, Source={StaticResource Loc}, Mode=OneWay}"
ContentStringFormat="{}{0}: "
Margin="0,5,5,5"
Grid.Row="3"/>
Expand Down
Loading

0 comments on commit eb5141e

Please sign in to comment.