1

I'm using the following code to add text to a image:

    private void AddText(Graphics graphics, FontDetails fontDetails, Rectangle destination)
    {
        using (GraphicsPath graphicsPath = new GraphicsPath())
        {
            graphicsPath.AddString(
                "My sample text",
                fontDetails.FontFamily,
                fontDetails.FontStyle,
                fontDetails.FontEmHeight,
                destination,
                fontDetails.FontStringFormat
            );

            graphics.FillPath(new SolidBrush(FontColour), graphicsPath);
        }
    }

This is working perfectly. I want to be able to apply an opacity effect to the text, but cannot seem to find an option to do this.

Any help would be greatly appreciated.

William Troup
  • 12,739
  • 21
  • 70
  • 98

1 Answers1

1

I think you can add an opacity value to the solid brush if you construct it like this:

SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(128, 0, 0, 255));
graphics.FillPath(semiTransBrush, graphicsPath);

When you fill a shape, you must pass a Brush object to one of the fill methods of the Graphics class. The one parameter of the SolidBrush constructor is a Color object. To fill an opaque shape, set the alpha component of the color to 255. To fill a semitransparent shape, set the alpha component to any value from 1 through 254.

https://msdn.microsoft.com/en-us/library/5s2dwfx1(v=vs.110).aspx

GJKH
  • 1,715
  • 13
  • 30