The weirdest bug I have ever seen
As some might remember, I am currently working with a team and we are trying to produce a reporting engine for an electric company which wants their reports in Word. Don't ask why,the customer is king
Anyways, my colleagues are largely in charge of generating the data and I'm in charge of producing the word pages. Now we got a few pages which have to display images. The images need to be resized. I resize them and since Word sucks I need to save them in between and get them out of the saved file and put them on the word page. The temporary images later get deleted.
Now the resizing works like a charm, but for some completely unknown reason to me, Word shows them in it's original size although there is no freaking possibility where it could have gotten it from since the only file there is, is the resized version.
public void addImageLarge(Word.Range range, byte[] inArray)
{
Image image = byteArrayToImage(inArray);
Image image2 = image.GetThumbnailImage(500,350, null, IntPtr.Zero);
image.Dispose();
int hash = randomhash();
string file = "" + @ConfigurationManager.AppSettings.Get("TempImages") + hash + ".jpg";
image2.Save(file);
imageList.Add(file);
Object rng = range;
range.Select();
Object savewith = true;
wrdApp.Selection.InlineShapes.AddPicture(file, ref oFalse, ref savewith, ref rng);
}
My guess is that there is something that binds the image to the original size. We will probably have to get the images resized before they are inserted into the database, a move I would probably recommend anyways since resizing also makes the images not look very good and the size we get is certainly not the original size of the image.
Comments
Another possibility is that Word has a default pix/inch setting for pictures overriding any other size instructions (until you manually rescale within word). Have you tried resampling the image instead of resizing?
Word.InlineShape wdimg = wrdApp.Selection.InlineShapes.AddPicture(file, ref oFalse, ref savewith, ref rng);
wdimg.Height = 300;
wdimg.Width = 500;