none
Word interop multiple image effects performance RRS feed

  • Question

  • Hi all!

     

    I'm using Word to insert an image, add some effects to it, save and extract the edited image. This all works great except of performance.

    Let me show some code..

     

    wordDoc.InlineShapes.AddPicture(filePath, ref _oFalse, ref _missing, ref _missing);
    
    if (actions.DoCorrection)
    {
           PictureEffect sharpen = wordDoc.InlineShapes[1].Fill.PictureEffects.Insert(MsoPictureEffectType.msoEffectSharpenSoften, -1);
           sharpen.EffectParameters[1].Value = correctParameters.Sharpen;
    
           PictureEffect brightnessContrast = wordDoc.InlineShapes[1].Fill.PictureEffects.Insert(MsoPictureEffectType.msoEffectBrightnessContrast, -1);
           brightnessContrast.EffectParameters[1].Value = correctParameters.Brightness;
           brightnessContrast.EffectParameters[2].Value = correctParameters.Contrast;
    
           PictureEffect saturation = wordDoc.InlineShapes[1].Fill.PictureEffects.Insert(MsoPictureEffectType.msoEffectSaturation, -1);
           saturation.EffectParameters[1].Value = correctParameters.Saturation;
    }
    
    if (actions.DoSoftEdge)
    {
           wordDoc.InlineShapes[1].SoftEdge.Type = MsoSoftEdgeType.msoSoftEdgeType4;
    }
    
    


    Adding every effect I add, and every parameter takes time!

    I think Word edits the picture as I add effects and parameters. This all ends up taking like 5 seconds on my work Phenom II 945, which is terrible.

    Thus I am wondering is there any way to speed things up. Maybe tell Word to process the picture only when I'm done adding effects.

    This is a major bottleneck in my apps performance.

     

    Any help will be greatly appreciated. 

    Thank you,

    Alex.

     

    Monday, October 10, 2011 10:13 AM

All replies

  • Hi Alex,

    Seems you are looking for WordApp.ScreenUpdating.


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Monday, October 10, 2011 10:22 AM
  • Hello Andrei!

     

    Thank you, but this did not solve my problem. Now I have this below, and it still performs exactly the same. Note that the actions shown above are only part of all that are done.

    _wordApp = new Word.Application();
    _wordApp.ScreenUpdating = false;
    _wordApp.Visible = false;
    
    _wordDoc = _wordApp.Documents.Add(ref _missing, ref _missing, ref _missing, ref _missing);
    
    EditPicture(fPathImage, _wordDoc, actions); //the snippet above is from this method..

    :)

    Monday, October 10, 2011 11:34 AM
  • You can try caching wordDoc.InlineShapes[1].Fill.PictureEffects in a variable.

    Also, consider generating such a document using Open XML; I believe, it shouldn't take that much time.


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Monday, October 10, 2011 11:46 AM
  • Hi Alex

    <<I think Word edits the picture as I add effects and parameters.>>

    Yes, definitely.

    <<Maybe tell Word to process the picture only when I'm done adding effects.>>

    If ScreenUpdating = False didn't help, then you aren't going to be able to do this. I think Andrei's suggestion to use OpenXML is going to be the only possibility to speed things up. If you need to do this in the UI, you can use the InsertXML method to "drop" it into the Word document, fully defined.


    Cindy Meister, VSTO/Word MVP
    Monday, October 10, 2011 1:19 PM
    Moderator
  • Thank you very much for your help. Open XML doesn't help as the functionality I need is not exposed through it.

     

    I don't need this in the UI Cindy, thank you.

     

    Thus, it seems this problem has no solution. Thanks for your help one more time.

    Cheers.

    Tuesday, October 11, 2011 1:02 PM
  • Hi Alex

    <<Open XML doesn't help as the functionality I need is not exposed through it.>>

    Are you sure? More things in the graphical area are exposed through Open XML than Word's object model...


    Cindy Meister, VSTO/Word MVP
    Tuesday, October 11, 2011 2:41 PM
    Moderator