Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by aewarnick
C#
Posted

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.

C#
  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...