Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone . I am trying to get a part of a screenshot but unfortunately I am getting ArgumentException when I am creating Bitmap. Here's a code :

public Bitmap bp(int x, int y, int width, int height)
{
Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(x, y, 0, 0, bitmap.Size, CopyPixelOperation.SourceCopy);
}
return bitmap;

}

When it's trying to make bitmap it throws ArgumentException. "Parameter isn't valid".
Can any one help to handle this ?

I Call this Function :

Bitmap ln = bp(Convert.ToInt32(textBox55.Text), Convert.ToInt32(textBox56.Text), Convert.ToInt32(textBox59.Text) - Convert.ToInt32(textBox55.Text), Convert.ToInt32(textBox56.Text) - Convert.ToInt32(textBox60.Text));

I am getting Parameters From TextBox
Posted
Updated 21-Sep-15 20:22pm
v2

1 solution

From that?
No, probably we can't - it is likely to be related to the values you are passing in.
So use the debugger, and gather some information.
Put a breakpoint on the first line of the method and run your code.
When it hits the breakpoint it will stop, and wait for you to tell it what to do. Start by looking at what the parameter values are: w, y, width, and height. Are they sensible?
If they are, step through the method until you find which line is causing the problem and look really closely at what it is being passed.

Then you will either have better info to fix this yourself, or you will have actual information at ask us with.

But we can't do any of that for you: we can't see your screen, access your HDD, run your code, or read your mind.
 
Share this answer
 
Comments
dave_bulac 22-Sep-15 3:05am    
thanks for advice. Have have made Debug and the main reason was that Height had negative meaning. Now I have changed code and it works. Thanks alot.
OriginalGriff 22-Sep-15 3:19am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900