This forum is in permanent archive mode. Our new active community can be found here.

The weirdest bug I have ever seen

edited September 2008 in Technology
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.

image

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

  • edited September 2008
    OK, I have no idea whether you actually manipulate the thumbnail, but if you do, there was a case a while ago where a blogger(iirc) cropped a nude picture of herself to make a head shot avatar picture. The change didn't propagate to the thumbnail stored within the meta data of the image file --> Internet hilarity.

    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?
    Post edited by Dr. Timo on
  • Wow, I was awaiting a picture of a weird insect. ^^
  • Wow, I was awaiting a picture of a weird insect. ^^
  • I'm expecting it's an issue with the size of the image object, but I can't be sure. I'll take a look through the MSDN when I get home.
  • Wow, I was awaiting a picture of a weird insect. ^^
    image
  • For anybody who cares, I fixed my problem by disposing of the resizing image code and directly resize the image in word. Took me some time to get to that though since Word manipulation via C# is not very well documented. I still have no clue why Word inserts the resized image in this small size.


    Word.InlineShape wdimg = wrdApp.Selection.InlineShapes.AddPicture(file, ref oFalse, ref savewith, ref rng);
    wdimg.Height = 300;
    wdimg.Width = 500;
Sign In or Register to comment.