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

Free Support Forum - aspose.com

Shape of ShapeType.Image- .Width and .Height set each other

Hi,


I use Shapes to absolutely position objects on a page. I have a mixture of ShapeType.TextBox and ShapeType.Image When the shape is a text box, I can set the height or width and it won’t affect the other. When the shape is an image, if I set the width, the width and height are updated to the same value. This same behaviour is occurring if I set the height. Is there anyway I can resize my image so it isn’t a square?

Document doc = new Document();

DocumentBuilder docBuilder = new DocumentBuilder(doc);

WriteShape(doc, docBuilder, ShapeType.TextBox);
WriteShape(doc, docBuilder, ShapeType.Image);

doc.Save(@“C:\temp\debug\example.doc”, SaveFormat.Doc);

private static void WriteShape(Document doc, DocumentBuilder docBuilder, ShapeType type) {

int height = 100;
int width = 200;
Shape shape = new Shape(doc, type);
// set width first, then height
shape.Width = width;
shape.Height = height;

docBuilder.InsertParagraph();

docBuilder.Writeln("");
docBuilder.Writeln(type.ToString());

docBuilder.Writeln("");
docBuilder.Writeln(“width : " + shape.Width);
docBuilder.Writeln(“height : " + shape.Height);
// set height first, then width
shape.Height = height;
shape.Width = width;

docBuilder.Writeln(””);
docBuilder.Writeln("width : " + shape.Width);
docBuilder.Writeln("height : " + shape.Height);

}

Hi David,


Thanks for your inquiry. Please try using the following code:

private static void WriteShape(Document doc, DocumentBuilder docBuilder, ShapeType type)

{

int height = 100;

int width = 200;

Shape shape = new Shape(doc, type);

if (shape.ShapeType == ShapeType.Image)

shape.AspectRatioLocked = false;

// set width first, then height

shape.Width = width;

shape.Height = height;

docBuilder.InsertParagraph();

docBuilder.Writeln("");

docBuilder.Writeln(type.ToString());

docBuilder.Writeln("");

docBuilder.Writeln("width : " + shape.Width);

docBuilder.Writeln("height : " + shape.Height);

// set height first, then width

shape.Height = height;

shape.Width = width;

docBuilder.Writeln("");

docBuilder.Writeln("width : " + shape.Width);

docBuilder.Writeln("height : " + shape.Height);

}


Hope, this helps.

Best regards,

Worked perfectly. Such a silly thing to miss. Thank-you!