位图(Int32,Int32,PixelFormat)抛出ArgumentException [英] Bitmap(Int32, Int32, PixelFormat) throws ArgumentException

查看:93
本文介绍了位图(Int32,Int32,PixelFormat)抛出ArgumentException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我试图获取截图的一部分但不幸的是,当我创建Bitmap时,我收到了ArgumentException。这是一个代码:



公共位图bp(int x,int y,int width,int height)

{

位图位图=新位图(宽度,高度,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

使用(图形g = Graphics.FromImage(位图))

{

g.CopyFromScreen(x,y,0,0,bitmap.Size,CopyPixelOperation.SourceCopy);

}

返回位图;



}



当它试图制作位图时会抛出ArgumentException。 参数无效。

任何人都可以帮忙解决这个问题吗?



我叫这个函数:



位图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获取参数

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

推荐答案

从那个?

不,可能我们不能 - 它可能与您传入的值有关。

所以使用调试器,并收集一些信息。

在方法的第一行放置一个断点并运行你的代码。

当它到达断点时它会停止,等你告诉它该怎么做。首先查看参数值是什么:w,y,width和height。它们是否合理?

如果它们是,请逐步执行该方法,直到找到导致问题的那条线并仔细查看它通过的内容。



然后你会有更好的信息来解决这个问题,或者你会得到实际的信息。



但我们不能为你做任何事情:我们看不到你的屏幕,访问你的硬盘,运行你的代码或读你的想法。
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.


这篇关于位图(Int32,Int32,PixelFormat)抛出ArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆