Merged in ScreenCap (pull request #70)
Fix ScreenCapture to include negative offset monitors. Approved-by: Jake Norbut <jake.norbut@bluetradesys.com> And also Kevin but he did it wrong.
This commit is contained in:
commit
3ab2b132f6
1 file changed
+12
-9
@@ -48,20 +48,23 @@ namespace mbts.ui.utility
|
||||
return null;
|
||||
}
|
||||
|
||||
static (int width,int height) screen_size() {
|
||||
static Int32Rect screen_size() {
|
||||
var config = Configuration.get<bts.config.System>();
|
||||
double width = SystemParameters.VirtualScreenWidth * config.dpi_ratio;
|
||||
double height = SystemParameters.VirtualScreenHeight * config.dpi_ratio;
|
||||
return ((int)width, (int)height);
|
||||
var dpi = config.dpi_ratio;
|
||||
return new Int32Rect(
|
||||
(int)(SystemParameters.VirtualScreenLeft * dpi),
|
||||
(int)(SystemParameters.VirtualScreenTop * dpi),
|
||||
(int)(SystemParameters.VirtualScreenWidth * dpi),
|
||||
(int)(SystemParameters.VirtualScreenHeight * dpi));
|
||||
}
|
||||
|
||||
private static BitmapSource capture() {
|
||||
(int width, int height) = screen_size();
|
||||
var screen = screen_size();
|
||||
IntPtr screen_dc = NativeMethods.GetDC(IntPtr.Zero);
|
||||
IntPtr mem_dc = NativeMethods.CreateCompatibleDC(screen_dc);
|
||||
IntPtr hbitmap = NativeMethods.CreateCompatibleBitmap(screen_dc, width, height);
|
||||
IntPtr hbitmap = NativeMethods.CreateCompatibleBitmap(screen_dc, screen.Width, screen.Height);
|
||||
NativeMethods.SelectObject(mem_dc, hbitmap);
|
||||
bool success = NativeMethods.BitBlt(mem_dc, 0, 0, width, height, screen_dc, 0, 0);
|
||||
bool success = NativeMethods.BitBlt(mem_dc, 0, 0, screen.Width, screen.Height, screen_dc, screen.X, screen.Y);
|
||||
BitmapSource bsource = Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||
NativeMethods.DeleteObject(hbitmap);
|
||||
NativeMethods.ReleaseDC(IntPtr.Zero, screen_dc);
|
||||
@@ -71,13 +74,13 @@ namespace mbts.ui.utility
|
||||
|
||||
|
||||
private static BitmapSource capture(int width_dest, int height_dest) {
|
||||
(int width_src, int height_src) = screen_size();
|
||||
var screen = screen_size();
|
||||
IntPtr screen_dc = NativeMethods.GetDC(IntPtr.Zero);
|
||||
IntPtr mem_dc = NativeMethods.CreateCompatibleDC(screen_dc);
|
||||
IntPtr hbitmap = NativeMethods.CreateCompatibleBitmap(screen_dc, width_dest, height_dest);
|
||||
NativeMethods.SelectObject(mem_dc, hbitmap);
|
||||
NativeMethods.SetStretchBltMode(mem_dc, 4/*HALFTONE*/);
|
||||
bool success = NativeMethods.StretchBlt(mem_dc, 0, 0, width_dest, height_dest, screen_dc, 0, 0, width_src, height_src);
|
||||
bool success = NativeMethods.StretchBlt(mem_dc, 0, 0, width_dest, height_dest, screen_dc, screen.X, screen.Y, screen.Width, screen.Height);
|
||||
BitmapSource bsource = Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||
NativeMethods.DeleteObject(hbitmap);
|
||||
NativeMethods.ReleaseDC(IntPtr.Zero, screen_dc);
|
||||
|
||||
Reference in new issue
Block a user