Where Are All The Pretty Graphics?

Creating custom EffectEnvironmentParameters in paint.net

April 2, 2017   -   Filed under: paint.net

This weekend I made a new plugin for paint.net: ‘Rubber Stamp’. It uses the the built-in Clouds effect to create a rubber stamp texture, and masks it the object on the canvas.

The thing about the Clouds effect is that it’s hard-coded to use the Primary and Secondary colors from the Colors window. When the Clouds effect is called from another effect (like my plugin), the Primary and Secondary colors are set to their default values of Black and White. Unfortunately, they are stuck at Black and White, as the PrimaryColor and SecondaryColor properties only have getters; no setters.

What we have to do is create a custom EffectEnvironmentParameters object. In its constructor, we can set the PrimaryColor and SecondaryColor properties to whatever we want.

using (EffectEnvironmentParameters envirParameters = new EffectEnvironmentParameters(ColorBgra.Red, ColorBgra.Blue, 0, EnvironmentParameters.GetSelection(srcArgs.Bounds), srcArgs.Surface))
    cloudsEffect.EnvironmentParameters = envirParameters;

Here I used the colors of Red and Blue. Since the Cloud effect doesn’t use the Brush Width, it’s just set it to 0. Next I passed the selection defined PdnRegion, and the source Surface.

Finally I set the Clouds effect’s EnvironmentParameters property to my own custom EffectEnvironmentParameters with Red and Blue.