简体   繁体   English

使用 Word VBA 将图片重新着色为黑白 75%

[英]Recolor picture to black and white 75% using Word VBA

I have using below, in Word document.我在 Word 文档中使用了下面的内容。

Sub Recolor()

Dim pic As InlineShape
Dim shp As Shape

Set pic = Selection.InlineShapes(1)
Set shp = Selection.ShapeRange(1)

pic.PictureFormat.ColorType = msoPictureBlackAndWhite
shp.PictureFormat.ColorType = msoPictureBlackAndWhite

End Sub

That performs Black and White 50%执行Black and White 50%

But I need Black and White 75% , How can coding 75% Recolor?但我需要Black and White 75% ,如何编码75%重新着色?

The VBA object model doesn't have hooks for all the color transformations that are in Word. VBA 对象模型没有用于 Word 中所有颜色转换的挂钩。 The 75% in the Black and White 75% refers to a color transformation parameter called Threshold in the XML. Black and White 75%中的 75% 指的是 XML 中称为Threshold的颜色转换参数。 But Threshold is not available in VBA.但是阈值在 VBA 中不可用。 Here's a macro that achieves a similar look by lowering brightness, increasing contrast and reducing saturation.这是一个通过降低亮度、增加对比度和降低饱和度来实现类似外观的宏。 You can play with the values and the command order, which makes a difference to the final appearance:您可以使用值和命令顺序,这会对最终外观产生影响:

Sub Recolor()
    Dim pic As InlineShape

    Set pic = Selection.InlineShapes(1)
    With pic
        With .PictureFormat
            .Brightness = 0.24
            .Contrast = 1
        End With
        With .Fill.PictureEffects
            .Insert(msoEffectSaturation).EffectParameters(1).value = 0
        End With
    End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM