PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Image size not displaying correctly https://forum.pdfsharp.net/viewtopic.php?f=2&t=1809 |
Page 1 of 1 |
Author: | aburdette [ Thu Oct 06, 2011 8:29 pm ] |
Post subject: | Image size not displaying correctly |
I am trying to display a user selected image on either a PDF or RTF document. I am using the same method to set up the document but somehow the RTF document comes out different in one way; non-square image's sizes do not render as specified. Bellow is the code I'm using to adjust the size of the image. Originally I was only setting either the height or the width depending on which one was larger but in an RTF document the size was not coming out correct and I wanted to see what would happen if I set each explicitly. This did nothing to correct the problem. using (System.Drawing.Image userImage = System.Drawing.Image.FromFile(userInfo.PicturePath)) { ImageOriginalHeight = userImage.Height; ImageOriginalWidth = userImage.Width; } paragraph = row.Cells[0].AddParagraph(); paragraph.Format.SpaceAfter = 2; image = paragraph.AddImage(userInfo.PicturePath); image.LockAspectRatio = true; if (ImageOriginalHeight > ImageOriginalWidth) { image.Height = new Unit(0.73, UnitType.Inch); image.Width = new Unit((0.73 / (double)ImageOriginalHeight) * (double)ImageOriginalWidth, UnitType.Inch); } else if (ImageOriginalWidth > ImageOriginalHeight) { image.Width = new Unit(0.73, UnitType.Inch); image.Height = new Unit((0.73 / (double)ImageOriginalWidth) * (double)ImageOriginalHeight, UnitType.Inch); } else { image.Height = image.Width = new Unit(0.73, UnitType.Inch); } |
Author: | () => true [ Sat Oct 08, 2011 10:24 pm ] |
Post subject: | Re: Image size not displaying correctly |
Hi! Just a wild guess: Do not use "image.LockAspectRatio = true;" if you want to set height and width explicitly. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |