Skip to content

Commit

Permalink
Added TrackBar to configure scaling (for Windows DPI/Scaling issues).
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneff committed Sep 18, 2017
1 parent b50c7aa commit 9c75e42
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 27 deletions.
41 changes: 38 additions & 3 deletions ComponentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public partial class CrashNSTLoadRemovalSettings : UserControl {
private bool drawingPreview = false;
private Bitmap previewImage = null;

private int scalingValue = 100;
private float scalingValueFloat = 1.0f;

private void initImageCaptureInfo()
{
imageCaptureInfo = new ImageCaptureInfo();
Expand Down Expand Up @@ -145,6 +148,9 @@ public Bitmap CaptureImage()
Screen selected_screen = Screen.AllScreens[-processCaptureIndex - 1];
Rectangle screenRect = selected_screen.Bounds;

screenRect.Width = (int)(screenRect.Width * scalingValueFloat);
screenRect.Height = (int)(screenRect.Height * scalingValueFloat);

Point screenCenter = new Point(screenRect.Width / 2, screenRect.Height / 2);


Expand Down Expand Up @@ -201,7 +207,11 @@ public Bitmap CaptureImageFullPreview(ref ImageCaptureInfo imageCaptureInfo, boo
Screen selected_screen = Screen.AllScreens[-processCaptureIndex - 1];
Rectangle screenRect = selected_screen.Bounds;

Point screenCenter = new Point(screenRect.Width / 2, screenRect.Height / 2);
screenRect.Width = (int)(screenRect.Width * scalingValueFloat);
screenRect.Height = (int)(screenRect.Height * scalingValueFloat);


Point screenCenter = new Point((int)(screenRect.Width / 2.0f), (int)(screenRect.Height / 2.0f));

if (useCrop)
{
Expand Down Expand Up @@ -258,7 +268,7 @@ public Bitmap CaptureImageFullPreview(ref ImageCaptureInfo imageCaptureInfo, boo



b = ImageCapture.PrintWindow(handle, ref imageCaptureInfo, full: true, useCrop: useCrop);
b = ImageCapture.PrintWindow(handle, ref imageCaptureInfo, full: true, useCrop: useCrop, scalingValueFloat: scalingValueFloat);
}


Expand All @@ -267,7 +277,14 @@ public Bitmap CaptureImageFullPreview(ref ImageCaptureInfo imageCaptureInfo, boo

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

processCaptureIndex = processListComboBox.SelectedIndex - numScreens;
if(processListComboBox.SelectedIndex < numScreens)
{
processCaptureIndex = -processListComboBox.SelectedIndex - 1;
}
else
{
processCaptureIndex = processListComboBox.SelectedIndex - numScreens;
}

selectionTopLeft = new Point(0, 0);
selectionBottomRight = new Point(previewPictureBox.Width, previewPictureBox.Height);
Expand Down Expand Up @@ -298,6 +315,7 @@ private void processListComboBox_DropDown(object sender, EventArgs e)
processListComboBox.Items.Clear();

numScreens = 0;

foreach (var screen in Screen.AllScreens)
{
// For each screen, add the screen properties to a list box.
Expand Down Expand Up @@ -432,6 +450,23 @@ private void previewPictureBox_MouseDown(object sender, MouseEventArgs e)
DrawPreview();
}

private void trackBar1_ValueChanged(object sender, EventArgs e)
{
scalingValue = trackBar1.Value;

if (scalingValue % trackBar1.SmallChange != 0)
{
scalingValue = (scalingValue / trackBar1.SmallChange) * trackBar1.SmallChange;

trackBar1.Value = scalingValue;

}

scalingValueFloat = ((float)scalingValue) / 100.0f;

scalingLabel.Text = "Scaling: " + trackBar1.Value.ToString() + "%";

DrawPreview();
}
}
}
82 changes: 62 additions & 20 deletions ComponentSettings.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions ImageCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CrashNSaneLoadDetector
{
Expand Down Expand Up @@ -159,8 +160,28 @@ public static Bitmap CaptureForegroundWindow()
return result;
}

public static SizeF GetCurrentDpiScale()
{
using (Form form = new Form())
using (Graphics g = form.CreateGraphics())
{
var dpi = new SizeF()
{
Width = g.DpiX,
Height = g.DpiY
};
// Calc the scale.
SizeF scale = new SizeF()
{
Width = dpi.Width / 96f,
Height = dpi.Height / 96f
};

public static Bitmap PrintWindow(IntPtr hwnd, ref ImageCaptureInfo info, bool full = false, bool useCrop = false)
return scale;
}
}

public static Bitmap PrintWindow(IntPtr hwnd, ref ImageCaptureInfo info, bool full = false, bool useCrop = false, float scalingValueFloat = 1.0f)
{
try
{
Expand All @@ -177,11 +198,12 @@ public static Bitmap PrintWindow(IntPtr hwnd, ref ImageCaptureInfo info, bool fu
IntPtr hdcwnd = DLLImportStuff.GetDC(hwnd);
IntPtr hdc = DLLImportStuff.CreateCompatibleDC(hdcwnd);

rc.Width = (int)(rc.Width * scalingValueFloat);
rc.Height = (int)(rc.Height * scalingValueFloat);




if(useCrop)
if (useCrop)
{
//Change size according to selected crop
rc.Width = (int)(info.crop_coordinate_right - info.crop_coordinate_left);
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file modified bin/Release/LiveSplit.CrashNSTLoadRemoval.dll
Binary file not shown.
9 changes: 9 additions & 0 deletions update.LiveSplit.CrashNSTLoadRemoval.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<updates>
<update version="1.4">
<files>
<file path="bin/Release/LiveSplit.CrashNSTLoadRemoval.dll" status="changed" />
</files>
<changelog>
<change>Added ability to select custom scale for Windows DPI Scaling issues.
This will allow you to change the capture scale if you have scaling enabled on Windows.</change>
</changelog>
</update>
<update version="1.3">
<files>
<file path="bin/Release/LiveSplit.CrashNSTLoadRemoval.dll" status="changed" />
Expand Down

0 comments on commit 9c75e42

Please sign in to comment.