如何将位图图像大小转换为双倍大小 [英] how to convert bitmap image size to double size

查看:85
本文介绍了如何将位图图像大小转换为双倍大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i有一个位图,现在我想将图像大小从int更改为double并更改为double我怎么能这样做

这是我的位图

位图bp = 位图(pictureBox1.Image,width,height); 



这个宽度和高度是int大小但是我想要双倍大小我该怎么办

最好的问候

解决方案

如果要将图像 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 image width and height into a couple of double variables (say dw, 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.


这篇关于如何将位图图像大小转换为双倍大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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