“参数无效。”在新的位图中 [英] "Parameter is not valid." in new Bitmap

查看:218
本文介绍了“参数无效。”在新的位图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了这个例外:



发生System.ArgumentException消息=参数无效。 Source =System.DrawingStackTrace:在System.Drawing.Bitmap..ctor(Int32宽度,Int32高度)的System.Drawing.Bitmap..ctor(Int32宽度,Int32高度,PixelFormat格式)...



以这种方式实例化新的位图:



位图resImage =  new 位图(宽度,高度); 
resImage.SetResolution( 600 600 );





其中宽度和高度是以像素为单位转换的尺寸,用户设置的尺寸为600 dpi,单位为cm,在此特定情况下为28x41 cm(A3格式图像)对应6614x9685像素。之后,我将从位图创建一个图形对象,并使用GDI +的方法绘制它。我需要一个高分辨率的图像,因为它将被添加到pdf文档中,我想要一个高质量的结果。



我从Windows应用程序获得此异常并且因为它是生成这种位图的连续过程,所以根据应用程序的类型和图像的尺寸,在重复的不同时间之后抛出异常。特别是,我在Windows应用程序中生成的图像数量和Web应用程序中的十分之一后获得错误。



我已经处理了所有图形对象,现在我真的不知道该怎么做!



为什么我获得此例外?我该如何解决这个问题?



提前感谢您的帮助!

解决方案

检查您的价值观 - 我刚试过我的代码:

  int  width =  6614 ; 
int height = 9685 ;
位图resImage = new 位图(宽度,高度);
resImage.SetResolution( 600 600 );

我没有例外。

所以,很可能,你传递的宽度和高度的值不是你想的 - 有在调试器中查看并确切地检查您传递给位图构造函数的像素值。



然后单步执行代码 - 正如我所说,它在这里工作。 / blockquote>

亲爱的朋友!

你解决了这个问题吗?

我和你有同样的问题。

你能告诉我如何处理这个问题吗?

谢谢!


你是否试图从流中创建位图?如果是,请检查您的信息流是否可以搜索。



  if (!strmftpdata.CanSeek)
{
}





如果它不可寻求那么你需要让它可以寻找。


I get this exception:

System.ArgumentException occurred Message="Parameter is not valid." Source="System.Drawing" StackTrace: at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)...

when I instantiate a new Bitmap in this way:

Bitmap resImage = new Bitmap(width, height); 
resImage.SetResolution(600, 600);



where width and height are the dimensions converted in pixel for 600 dpi of the size set by the user in cm, which is in this specific case 28x41 cm (A3 format image) corresponding to 6614x9685 pixel. After that I will create a graphics object from the bitmap and draw on it with the methods of GDI+. I need an high resolution image because it is going to be added to a pdf document and I want a great quality result.

I get this exception both from a windows application and a web one, but because it is a continous process of generating this kind of bitmaps, the exception is thrown after a different times of reiteration according to the type of application and the dimension of the image. In particular, I obtain the error after an order of hundreths of images produced in the windows app and tenths in the web app.

I have already dispose all the graphics objects and now I really don't know what to do!

Why I obtain this exception? How can I solve the problem?

Thanks in advance for every help!

解决方案

Check your values - I just tried in in my code:

int width = 6614;
int height = 9685;
Bitmap resImage = new Bitmap(width, height);
resImage.SetResolution(600, 600);

And I don't get an exception.
So, most likely, the values you are passing in for width and height are not what you think - have a look in the debugger and check exactly what pixel values you are passing to the bitmap constructor.

Then single step your code - as I say, it works here.


Dear friend!
Did you solve this problem?
I have the same problem as you.
Could you tell me how to deal with this problem?
Thank you!


are you trying to create bitmap from stream? if yes, please check your stream is seek-able or not.

if (!strmftpdata.CanSeek)
{
}



if it is not seek-able then you need to make it seek-able.


这篇关于“参数无效。”在新的位图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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