We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

EMF ratio is not preserved when specifying width/height

Code I am using (emf file is attached as a zip file). The first image is good, but the ratio of the second one is wrong:


using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Words;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DocumentBuilder builder = new DocumentBuilder();

System.Drawing.Image img = System.Drawing.Image.FromFile(“c:\temp\t.emf”);
builder.InsertImage(img); // WORKS FINE
builder.InsertImage(img, img.Width / 2, img.Height / 2); // RATIO IS WRONG

builder.Document.Save(“c:\temp\t.doc”);
}
}
}

Hi Yongwen,

Thanks for your inquiry. Please use the ImageData.ImageSize property to achieve your requirement as shown in following code snippet. The property gets the information about image size and resolution. Hope this helps you. Please let us know if you have any more queries.

DocumentBuilder builder = new DocumentBuilder();

System.Drawing.Image img = System.Drawing.Image.FromFile(MyDir + "in.emf");

builder.InsertImage(img); // WORKS FINE

//builder.InsertImage(img, img.Width / 2, img.Height / 2); // RATIO IS WRONG

Shape image = builder.InsertImage(img);

ImageSize size = image.ImageData.ImageSize;

image.Width = size.WidthPoints /2;

image.Height = size.HeightPoints / 2;

builder.Document.Save(MyDir + "Out.doc");


Following code example shows how to resize an image shape.

DocumentBuilder builder = new DocumentBuilder();

// By default, the image is inserted at 100% scale.

Shape shape = builder.InsertImage(MyDir + "Aspose.Words.gif");

// It is easy to change the shape size. In this case, make it 50% relative to the current shape size.

shape.Width = shape.Width * 0.5;

shape.Height = shape.Height * 0.5;

// However, we can also go back to the original image size and scale from there, say 110%.

ImageSize imageSize = shape.ImageData.ImageSize;

shape.Width = imageSize.WidthPoints * 1.1;

shape.Height = imageSize.HeightPoints * 1.1;

builder.Document.Save(MyDir + "Image.ScaleImage Out.doc");