aewarnick Posted May 7, 2003 Posted May 7, 2003 (edited) Am I missing something? When I use my method the ratio of the old size to the new size is exactly the same but it is not proportional when it saves to disk. The call and creation of the bitmap: Bitmap b=new Bitmap(file); Size size= a.graphics.ProportionalSize(b.Size, new Size(Convert.ToInt32(this.widthTB.Text), Convert.ToInt32(this.hieghtTB.Text))); Bitmap B=new Bitmap(b, size); B.Save(thisDir+"\\x\\"+im, ImageFormat.Bmp); The method that returns a proportional size: public static Size ProportionalSize(Size imageSize, Size newSize) { Size size=new Size(imageSize.Width, imageSize.Height); int ratio= size.Width-size.Height; if(size.Width < newSize.Width && size.Height < newSize.Height) { MessageBox.Show(ratio+""); while(size.Width < newSize.Width && size.Height < newSize.Height) { size= new Size(size.Width+1, size.Height+1); } ratio= size.Width-size.Height; MessageBox.Show(ratio+""); } else { ratio= size.Width-size.Height; MessageBox.Show(ratio+""); while(size.Width > newSize.Width || size.Height > newSize.Height) { size= new Size(size.Width-1, size.Height-1); } MessageBox.Show(size+" "+newSize); } ratio= size.Width-size.Height; MessageBox.Show(ratio+""); if(size.Width < 1) size=new Size(size.Width+-size.Width+1, size.Height-size.Width-1); if(size.Height < 1) size=new Size(size.Width-size.Height-1, size.Height+-size.Height+1); return size; } Let's say that I sent a size of 400, 295 to the method. Proportionately I get 400, 232 which is mathmatically correct. But it is not, when I look at the image proportional to the original. I used 400, 295 because that is what IrfanView says the proportions should be. What am I missing? There must be something I don't know about resizing images. Edited May 7, 2003 by aewarnick Quote C#
aewarnick Posted May 9, 2003 Author Posted May 9, 2003 Does anyone have an idea what I do not know about resizing images. Mathmatically, my method works correctly but according to IrfanView you do not resize the images mathmatically correct but with some other calculation. Please help if you know what I do not. Quote C#
aewarnick Posted May 14, 2003 Author Posted May 14, 2003 I had to multiply instead of add. And I multiplied increasingly by .001. Quote C#
*Experts* Nerseus Posted May 14, 2003 *Experts* Posted May 14, 2003 I'm not sure what you're trying to do. You say: Let's say that I sent a size of 400, 295 to the method. Proportionately I get 400, 232... I'm confused because your function takes two params and returns a new Size. You only mention passing one value and getting back a new value. I haven't looked at your code, but are you just trying to resize an image? Why not just multiply the width and height by the *same* value? If you need to base that scaling factor based on a maximum height or width (the second param maybe?) then you just need to figure out which dimension (width or height) is bigger and get your scaling value from that. If that's all you need, I can give you my 3 or 4 line version. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
aewarnick Posted May 15, 2003 Author Posted May 15, 2003 Thank you Nerseus, that is exactly right. I changed my code around and it works perfectly now and is faster. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.