更新时间:2022-10-26 22:42:08
如果要将图像width
和height
存储到几个中双
变量(比如dw
,dh
),然后只需分配它们:double dw = width;
double dh = height;
您不能在那里指定double值。您正在使用Bitmap构造函数的此签名。位图(图像, Int32 , Int32 );
http://msdn.microsoft.com/en-us/library/334ey5b7(v = vs.110 ).aspx [ ^ ],它永远不会接受双重值。
但是你可以在传递double时将double转换为整数,但是传递double值是行不通的。或者,您可以将Width和Height属性返回的int值转换为加倍以便在代码中工作。
在WinForms控件中''大小和'位置属性仅为整数。
在WPF中,这些属性使用double。
WinForms System.Drawing中的'SizeF结构几乎总是用于特殊Paint事件中的操作。
但是,如果你正在对WinForms中的控件进行一些重新调整,并希望根据比率提高精度:在缩放之前计算Float Type值,然后将'SizeF'转换为'Size(整数)以缩放:// 不是一个完整的代码示例
// 您将在EventHandler中执行的操作示例表格'SizeChanged事件
float xRatio,yRatio;
xRatio =( float )(newFormSize.Width)/ oldFormSize.Width;
yRatio =( float )(newFormSize.Height)/ oldFormSize.Height;
SizeF newSize = new SizeF(xRatio * pictureBox1.Width,pictureBox1.Height * yRatio);
pictureBox1.Size = newSize.ToSize();请求完整的代码示例:是的,使用这样的比率可以提供更准确的缩放。
Hi
i have a bitmap and now i want to change the image size from int to double and change with double how can i do it
this is my bitmap
Bitmap bp = new Bitmap(pictureBox1.Image, width, height);
this "width" and "height" are in int size but i want double size how can i do it
Best Regards
If you want to store the imagewidth
andheight
into a couple ofdouble
variables (saydw
,dh
), then just assign them:double dw = width; double dh = height;
You cannot assign a double value there. You are using this signature of the Bitmap constructor.Bitmap(Image, Int32, Int32);
http://msdn.microsoft.com/en-us/library/334ey5b7(v=vs.110).aspx[^], and it will never accept a double value in it.
You can however still convert the double to integer while passing it but passing a double value would not work. Or you can convert the int values returned by Width and Height properties to double for working in your code.
In WinForms Controls' 'Size and 'Location properties are integer only.
In WPF these properties use double.
The 'SizeF structure in WinForms System.Drawing is used almost always for special operations in the Paint Event.
However, if you are doing some re-sizing of Controls in WinForms and want increased accuracy based on ratios: calculate Float Type values before scaling, then convert the 'SizeF to 'Size (integer) to scale with:// not a complete code example // example of what you would do in an EventHandler for a Form 'SizeChanged event float xRatio, yRatio; xRatio = (float)(newFormSize.Width) / oldFormSize.Width; yRatio = (float)(newFormSize.Height) / oldFormSize.Height; SizeF newSize = new SizeF(xRatio * pictureBox1.Width, pictureBox1.Height * yRatio); pictureBox1.Size = newSize.ToSize();Complete code example on request: yes, using ratios like this does give more accurate scaling.