How to read the color settings (Color Tone, Recolor) available under "Picture Tools" Format in the PowerPoint VSTO Addin?

Viewed 378

I'm working on a VSTO add-in that adds a chart image in the slide.The chart is coming from WinForms DataVisualization.Charting library. We are using this instead of PowerPoint native charts for performance reasons.

I want to get the Picture Format Setting specifically the Color Drop-down settings applied by the user when replacing the image so that it feels the same.

enter image description here

I've tried searching for it, even tried to find it by looking at Shape.PictureFormat property and how it changes when we change from the ribbon.

More Information

With the help of Format Picture sidebar pane, I was able to see what is being updated when we change something in color drop-down.

Format Picture sidebar pane

For example the Color Saturation changes the saturation (third one in Picture Color group of sidebar).
The Color Tone changes the Temperature but the Recolor does not change anything and unfortunately this is the one I want to preserve when updating image.

After some research I found that a Recolor method exists but it is only available for Office Publisher app. Upon digging deeper into the presentation file I found there is an additional tag inside the image tag with in the slide.xml file.

<a:duotone>
    <a:prstClr val="black"/>
    <a:schemeClr val="accent3">
        <a:tint val="45000"/>
        <a:satMod val="400000"/>
    </a:schemeClr>
</a:duotone>

But still looking for how can I get this information during run-time and use it.

2 Answers

Here is the solution I used for anyone else who might need it.

To copy a picture formatting we can use Shape.PickUp on the source and Shape.Apply on the destination to copy most of the formatting.

Shape.PickUp - Copies the formatting of the specified shape. Use the Apply method to apply the copied formatting to another shape.

Shape.Apply - Applies to the specified shape formatting that's been copied by using the PickUp method.

The following VBA code demonstrates some of the color formatting object model for a PowerPoint Shape. To get the Saturation and ColorTone, specifically, PictureEffect.EffectParameter is required. EffectParameter has Name and Value properties that reflect which Saturation and Color Temperature is used (read/write).

Sub ShapeColorFormatting()
    Dim PP As Presentation
    Dim s As Slide
    Dim shp As Shape
    Dim b As Double, c As Long 'MsoPictureColorType
    Dim lPE As Long, lEp As Long, p As Long, e As Long
    Dim pe As PictureEffect, ep As EffectParameter

    Set PP = ActivePresentation
    Set s = PP.Slides(1)
    Set shp = s.Shapes(s.Shapes.Count)
    Debug.Print shp.Name

    b = shp.PictureFormat.Brightness
    c = shp.PictureFormat.ColorType

    lPE = shp.Fill.PictureEffects.Count
    For p = 1 To lPE
        Set pe = shp.Fill.PictureEffects(p)
        For e = 1 To pe.EffectParameters.Count
            Set ep = pe.EffectParameters(e)
            Debug.Print ep.Name, ep.Value
        Next e
    Next p

    Debug.Print shp.Fill.ForeColor.TintAndShade, _
                shp.Fill.BackColor.ObjectThemeColor, _
                shp.Fill.ForeColor.ObjectThemeColor
End Sub
Related