Position/scale image after programmatically pastin

2019-09-02 11:20发布

问题:

I'm creating a Word 2010 document using C# and Microsoft.Office.Interop.Word. Using the Range.Paste method, I insert a bitmap (from RAM) at a specified bookmark:

Word.Bookmark bookmark = document.Bookmarks.get_Item(ref oBookmark);
Clipboard.SetDataObject(image);
bookmark.Range.Paste();

This bookmark is placed inside a frame (created with the "Insert Frame" command), hence the pasted image is placed inside the frame. Now, the image is automatically scaled to fit the frame horizontally. This is good! But, it does not perform this type of scaling vertically! This causes the bottom of the image to be obscured by any object under the frame:

Frame A should not be resized!

Q: How can I make sure the image is scaled both horizontally and vertically, keeping the frame's original size?

回答1:

Solution: Read the size of the frame and then properly scale the image before pasting it.