質問

I'm a bit mystified by this. We have a c#/WPF screen capture tool that grabs a section of the desktop using Graphics.CopyFromScreen.

It works fine on dozens of different machines, including XP, Win7 and at least one Windows8 VM.

We have encountered one Acer ZS600 which has Win8 on it, and we're seeing a bizarre effect I can't figure out.

When you capture, it grabs an image of the correct size, but the wrong position. It is offset to the top and left. Not by a fixed amount. When the capture window is at the screen 0,0 position it is fine, but as you move the capture window away from origin, the offset increases.

I've been though the code and found that the window position (this.Top and this.Left) are reporting the wrong numbers.

Even more strangely, we have tried this on an Acer Z5771, which is virtually the same hardware setup, except it uses Windows 7. We have tried updating the Zs600 graphics driver, but it had no effect.

Does anyone understand this, or suggest a fix or workaround?

Edit: I've put together a simple app which, on the problem machine, shows the effect. On my dev machine it works fine. Download here: https://s3-eu-west-1.amazonaws.com/kdownload/Tools/CaptureTool_app.zip

Or download a compiled version: https://s3-eu-west-1.amazonaws.com/kdownload/Tools/capturetest.exe

EDIT: Here's two Screenshots of the capture app in use on the problem system. https://s3-eu-west-1.amazonaws.com/kdownload/Tools/ProblemScreencap.png (Edit - in that screenshot I had the displayed numbers for x&y switched with width&height, now fixed in the code uploaded, please ignore this)

役に立ちましたか?

解決

It could be because the OS Dpi setting is set above 100%.

You could make a helper method to check and convert to the correct location based on the current OS dpi.

Something like.

public Point GetDpiSafeLocation(Point location)
{
    PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow);
    if (source != null)
    {
        double dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11;
        double dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22;
        return new Point(location.X * 96.0 / dpiX, location.Y * 96.0 / dpiY);
    }
    return location;
}

Usage:

 var point = GetDpiSafeLocation(new Point(Left, Top));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top