Hi
Is there a possibility to use IWPicture object to insert image in the word document that's using merge fields? Currently when merging picture I am using following code:
private void MailMerge_MergeImageField(object sender, MergeImageFieldEventArgs args)
{
if (args.FieldValue != null)
{
var stream = new System.IO.MemoryStream();
Image image = (Image)args.FieldValue;
ImageFormat imageFormat = image.RawFormat;
image = new Bitmap(image, GetNewSize(args.CurrentMergeField.FieldCode, image.Size));
image.Save(stream, imageFormat);
stream.Position = 0;
args.ImageStream = stream;
}
}
In the method GetNewSize, I am calculating size of the image to fit in certain dimensions. This code works, however picture quality is lost. I noticed however when I use your IWPicture that by resizing picture quality isn't lost. For example if I use following code, to add picture directly in the document (in text box) picture looks much nicer:
Private Sub FillTextboxWithUserImage(textBox As WTextBox, paragraph As IWParagraph)
Dim profileImage = GetProfileImage(candidateID)
Dim backup As Image = New Bitmap(profileImage)
paragraph.Text = ""
textBox.TextBoxFormat.FillEfects.Type = BackgroundType.NoBackground
Dim picture As IWPicture = paragraph.AppendPicture(backup)
Dim scalingFactor As Single = Math.Min(textBox.TextBoxFormat.Height / picture.Height, textBox.TextBoxFormat.Width / picture.Width) * 100
picture.WidthScale = scalingFactor
picture.HeightScale = scalingFactor
End Sub
If I use this method, then picture quality is somehow preserved even though it is correctly resized.