Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 位图(Int32、Int32、PixelFormat)引发异常_C#_.net - Fatal编程技术网

C# 位图(Int32、Int32、PixelFormat)引发异常

C# 位图(Int32、Int32、PixelFormat)引发异常,c#,.net,C#,.net,我试图获取屏幕截图的一部分,但不幸的是,当我创建位图时,我得到了ArgumentException。这里有一个代码: 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.FromIm

我试图获取屏幕截图的一部分,但不幸的是,当我创建
位图时,我得到了
ArgumentException
。这里有一个代码:

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;
}
当它试图制作位图时,会抛出:

例外。“参数无效”

有人能帮忙处理吗

我把这个函数称为:

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));

我从
TextBox

获取参数,您必须将宽度和高度作为0传递给此方法


宽度和高度必须大于0。

您可以共享stacktrace的停车场吗?您如何调用此方法??您是否正在传递有效的参数??你能发布完整的stacktrace吗?文本框中有哪些数字(如果有的话)?它们有多大?位图不能任意大..我在屏幕上点击并获得鼠标点击的坐标。例如,在textbox1=X坐标和textBox2=Y坐标中。请检查您的参数值。您传入的参数是什么?