views:

337

answers:

1

Hello all, I have a gloss method and I'm trying to get a inverted half moon like effect. On the below code I'd like to remove just above bottom half of this ellipse and then draw it. Does anyone know how I might begin to do that?

PS. The gloss is also turning out too white. I've tried messing with the alpha to no avail, does anyone know any tricks to make the gloss more subtle? Thank you

  /// <summary>
        /// Applies gloss to clock
        /// </summary>
        /// <param name="e"></param>
        private void DrawGloss(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            float x = ((float)_CenterX / 1.1F) / _PI;
            float y = ((float)_CenterY / 1.2F) / _PI;
            float width = ((this.ClientSize.Width / 2)) + _hourLength;
            float height = ((this.ClientSize.Height / 2)) + _hourLength;

            RectangleF glossRect = new RectangleF(
           x + (float)(width * 0.10),
           y + (float)(height * 0.07),
           (float)(width * .8),
           (float)(height * 0.4));


            LinearGradientBrush gradientBrush =
                new LinearGradientBrush(glossRect,
                Color.FromArgb((int)50, Color.Transparent),
                glossColor,
                LinearGradientMode.BackwardDiagonal);
            g.FillEllipse(gradientBrush, glossRect);


        }
+4  A: 

FillPie could give you exactly half a circle. Otherwise you'd have to use FillClosedCurve or FillPath to get slightly less than half a circle, or draw a half-circle onto an intermediate, slightly smaller Bitmap and copy that back onto your main Bitmap with DrawImage.

For a more subtle gloss effect, I think you just need to change your LinearGradientBrush code to:

LinearGradientBrush gradientBrush =                
    new LinearGradientBrush(glossRect,                
    Color.Transparent,                
    Color.FromArgb((int)50, glossColor),                
    LinearGradientMode.BackwardDiagonal);

Your original gradient was going from fully transparent to full glossColor.

MusiGenesis
+1, and FillPath is the most complex (and most powerful) approach. See http://msdn.microsoft.com/en-us/library/b5hek5ky.aspx
Henk Holterman
Now the gloss seems so subtle as to hardly be there at all. :( I wonder if there isn't a happy medium? Thanks for your responses everyone!
stormist
@stormist: try increasing the number in the "Color.FromArgb((int)50, glossColor)" parameter from 50 to 128 (or thereabouts). This number represents the alpha channel value (or the opacity) of the color you're deriving from glossColor, and can range from 0 (completely transparent) to 255 (completely opaque, or equal to glossColor). A value of 128 would be literally the "happy medium".
MusiGenesis
@stormist: and you can thank me by clicking that little checkmark next to my answer. :)
MusiGenesis
I forgot to mention one other useful trick: set the SmoothingMode property of your Graphics object to HighQuality before calling FillPie (or whatever other drawing methods you're using). The default mode is pixelly and generally pretty crappy-looking.
MusiGenesis