PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 9:08 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Apr 23, 2015 10:16 am 
Offline

Joined: Thu Apr 23, 2015 9:46 am
Posts: 1
Hello everybody,

If I set image resolution in code:

Code:
MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
var section = AddSection(document, pageSetup);

var image = section.AddImage("image.png");
image.Resolution = 300;

rtfRenderer.Render(document, test.rtf, ".")


then I get error
Quote:
Specified cast is not valid
in method
Quote:
MigraDoc.RtfRendering.ImageRenderer.CalculateImageDimensions
on line
Code:
horzResolution = (float)GetValueAsIntended("Resolution");


Problem is in cast double result GetValueAsIntended("Resolution") to float. I solved problem with following proposed patch.

Code:
 .../MigraDoc.RtfRendering/ImageRenderer.cs             | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/pdfsharp/MigraDoc/code/MigraDoc.RtfRendering/MigraDoc.RtfRendering/ImageRenderer.cs b/pdfsharp/MigraDoc/code/MigraDoc.RtfRendering/MigraDoc.RtfRendering/ImageRenderer.cs
index 273cbe9..f824631 100644
--- a/pdfsharp/MigraDoc/code/MigraDoc.RtfRendering/MigraDoc.RtfRendering/ImageRenderer.cs
+++ b/pdfsharp/MigraDoc/code/MigraDoc.RtfRendering/MigraDoc.RtfRendering/ImageRenderer.cs
@@ -205,23 +205,23 @@ namespace MigraDoc.RtfRendering
         //System.Drawing.Bitmap bip2 = new System.Drawing.Bitmap(imageFile);
         XImage bip = XImage.FromFile(this.filePath);
 
-        float horzResolution;
-        float vertResolution;
+        double horzResolution;
+        double vertResolution;
         string ext = Path.GetExtension(this.filePath).ToLower();
-        float origHorzRes = (float)bip.HorizontalResolution;
-        float origVertRes = (float)bip.VerticalResolution;
+      double origHorzRes = bip.HorizontalResolution;
+      double origVertRes = bip.VerticalResolution;
 
         this.originalHeight = bip.PixelHeight * 72 / origVertRes;
         this.originalWidth = bip.PixelWidth * 72 / origHorzRes;
 
         if (this.image.IsNull("Resolution"))
         {
-          horzResolution = (ext == ".gif") ? 72 : (float)bip.HorizontalResolution;
-          vertResolution = (ext == ".gif") ? 72 : (float)bip.VerticalResolution;
+         horzResolution = (ext == ".gif") ? 72 : bip.HorizontalResolution;
+         vertResolution = (ext == ".gif") ? 72 : bip.VerticalResolution;
         }
         else
         {
-          horzResolution = (float)GetValueAsIntended("Resolution");
+          horzResolution = (double)GetValueAsIntended("Resolution");
           vertResolution = horzResolution;
         }
 
@@ -233,9 +233,9 @@ namespace MigraDoc.RtfRendering
 
         bool scaleWidthIsNull = this.image.IsNull("ScaleWidth");
         bool scaleHeightIsNull = this.image.IsNull("ScaleHeight");
-        float sclHeight = scaleHeightIsNull ? 1 : (float)GetValueAsIntended("ScaleHeight");
+      double sclHeight = scaleHeightIsNull ? 1 : (double)GetValueAsIntended("ScaleHeight");
         this.scaleHeight = sclHeight;
-        float sclWidth = scaleWidthIsNull ? 1 : (float)GetValueAsIntended("ScaleWidth");
+      double sclWidth = scaleWidthIsNull ? 1 : (double)GetValueAsIntended("ScaleWidth");
         this.scaleWidth = sclWidth;
 
         bool doLockAspectRatio = this.image.IsNull("LockAspectRatio") || this.image.LockAspectRatio;


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group