Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
Posted

If you want to store the image width and height into a couple of double variables (say dw, dh), then just assign them:
C#
double dw = width;
double dh = height;
 
Share this answer
 
Comments
Avenger1 14-Nov-14 7:57am    
Hiif i do it it can't use in bitmap
You cannot assign a double value there. You are using this signature of the Bitmap constructor.

C#
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.
 
Share this answer
 
v2
Comments
Avenger1 14-Nov-14 8:00am    
OK, if i want to make image in bigger size than int, what should i do?
Afzaal Ahmad Zeeshan 14-Nov-14 8:07am    
Sadly, you will have to stick to only Int32. But what more you can want?

Int32 can create an image with 2,147,483,647 width and height dimension. You can read for the maximum value of them here. So obviously, you are not going to use an image that might want a bigger size than this one. :)
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:
C#
// 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.
 
Share this answer
 
Comments
Avenger1 14-Nov-14 8:02am    
i don't want to change picturebox size, i want to change image size
BillWoodruff 14-Nov-14 23:43pm    
So, revise your question so it's clear what you are talking about.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900