Jump to content

C# Graphics +1


JohnOne
 Share

Go to solution Solved by jvanegmond,

Recommended Posts

System.Drawing.Graphics

 

Creating a simple screen capture class, and getting an error I've not seen before.

Wondering if any of you folks now anything about it.

 

The error is this.. 

win32exception the specified program requires a newer version of windows

The weird thing is it runs in the IDE (VS2010) and I'm running win 7.

But the production exe produces the error.

The Documentation does not say it needs win 8 or higher, and a remark suggests it is good for win XP.

 

Here is the offending code.

hGfx = Graphics.FromImage(hBmp);
hGfx.CopyFromScreen(
     x, 
     y, 
     0, 
     0, 
     size);
Cannot find a close enough match for the full error in web search.

EDIT:

Sorry it is the CopyFromScreen method that causes it, not FromImage.

EDIT2: (+1)

Also, if anyone knows, how expensive are Thread safe delegate calls to get a property from form?

My thread employs a tight loop and it needs to know when a property of the form changes, so might need to check the property each iteration, unless I can find a way for a form event handler to run in my worker thread.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The only thing I can say is that if the error only crops up in the production exe then there are some compiler settings that you should investigate.  I'm no expert on this so take that as you will.

Link to comment
Share on other sites

  • Solution

When it runs in Visual Studio in Debug mode but not in production when you build it for Release, then optimizations are immediately suspect.

Try this:

using (hGfx = Graphics.FromImage(hBmp)) {
    hGfx.CopyFromScreen(x, y, 0, 0, size);
}

Also found this on with a similar problem and same solution: http://stackoverflow.com/questions/6788276/runtime-error-after-taking-screenshots-in-net

Link to comment
Share on other sites

Cheers Manadar, this helped from the link you provided.

1. "System.ComponentModel.Win32Exception (0x80004005): The parameter is incorrect" in CopyFromScreen occurs when there's no primary desktop visible - for example, in service mode, or (in my case) when user presses "Ctrl-Alt-Del" in Windows 7/8.

 

Although my desktop is indeed visible, the window I was capturing was not, needed to change where the code was called from.

Thanks.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...