Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF giving incorrect size values
    primarykey
    data
    text
    <p>I have a WPF application in which I am attempting to take a screen grab of a WindowsFormsHost control. To do this I am doing a Graphics.CopyFromScreen. On most boxes we have tested on this works perfect, however we have one machine that is not grabbing the right size values. The width and height that are given by WPF do not match the actual width and height of the control. When snooping, the incorrect values show for the ActualWidth and ActualHeight of the control as well. Even further, when I snoop the main window (which is maximized), I get an ActualWidth of 1550 and and ActualHeight of 840, but my screen resolution is 1920x1080. I would understand being a few pixels off for borders, margins, etc, but to have WPF tell me my maximized window is 370 pixels shorter in width than the actual screen just doesn't make sense. Can anyone explain this behaviour?</p> <p>The following is the code being used to capture an image of the control:</p> <pre><code>public static Bitmap CreateBitmapFromVisual(this FrameworkElement target) { Rect bounds = VisualTreeHelper.GetDescendantBounds(target); if (bounds.Width == 0 &amp;&amp; bounds.Height == 0) return null; System.Windows.Point p0 = target.PointToScreen(bounds.TopLeft); System.Drawing.Point p1 = new System.Drawing.Point((int) p0.X, (int) p0.Y); Bitmap image = new Bitmap((int)bounds.Width, (int)bounds.Height); Graphics imgGraphics = Graphics.FromImage(image); imgGraphics.CopyFromScreen(p1.X, p1.Y, 0, 0, new System.Drawing.Size((int) bounds.Width, (int) bounds.Height)); return image; } </code></pre> <p>Here is an image to better describe what I'm talking about:</p> <p><img src="https://i.stack.imgur.com/KUCVu.png" alt="enter image description here"></p> <p>As you can see, snoop is saying that the actualwidth and actualheight of the WindowsFormsHost is 486x336. Any debug information I log says the same thing. However, when I Print Screen and crop to the control in paint, the actual size is 608x423, a sizeable difference.</p> <p>As a further update, it seems like the width given by wpf is roughly 80% of the actual width. This is true for both the control and the window.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload