Image Scaling In Microsoft Word Using C# RRS feed

  • Question

  • Hi,

    I am trying insert the IMAGE JPG with 2048*2048(Pixels)(width*Height). The actual declared Max_Width=410, and finding the AspectRatio and scaling the Image and inserting in the Document Using C#. The written code is working for the Document which Less Than 1900Pixels. And when i Calculating the AspectRatio for the Image 2048pixels it showing aspect Ratio with 20% and Applying but its not getting applyed. and also when i insert an Image in the Document it showing the Acpect Ratio as 100%. The below code which i have written to do this.

     using (b = new Bitmap(finalImageFilePath))
                        if (b.Width > 410)
                            sourceWidth = b.Width;
                            sourceHeight = b.Height;
                            aspectRatio = ((414.0F / (float)b.Width)) * 100.0F;
                            sourceWidth = 100F;


     inLineShape = imageTable.Rows[1].Range.InlineShapes.AddPicture(finalImageFilePath, ref GlobalObjects.bFalse, ref GlobalObjects.bTrue, ref oRange);
                        inLineShape.ScaleWidth = aspectRatio;
                        inLineShape.ScaleHeight =aspectRatio;
                        inLineShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;


     Thank You..


    Friday, December 16, 2011 4:58 AM


  • I sugguest that after you add the image with the command inLineShape = imageTable.Row .... your next command should be to lock the aspect ratio followed by only one of the scale commands.  Use either ScaleWidth or ScaleHeight but not both.

    I don't fully follow what you are trying to do with the aspectRatio setting and I've got to run my wife to an appointment so I'll check back later and see if there's a need for more help.

    Kind Regards, Rich ...
    Friday, December 16, 2011 10:58 AM