System.Drawing

Scarshady

New Member
Can anyone show me how to create a circle with a radial gradient fill? I can do it with a linear fill, but do not understand how to define a PathGradientBrush that uses a Path to fill the circle. To do a linear gradient, I used:<BR><BR>Bitmap objBmp = new Bitmap(400, 400);<BR> Graphics objGrx = Graphics.FromImage(objBmp);<BR> Brush brsDarkBlue = new SolidBrush(System.Drawing.Color.FromArgb(51, 102, 153));<BR><BR> Rectangle myRectangle = new Rectangle(0, 0, 400, 400);<BR> LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(<BR> myRectangle,<BR> Color.White,<BR> Color.FromArgb(180, 51, 102, 153), <BR> LinearGradientMode.BackwardDiagonal);<BR><BR> <BR> objGrx.FillRectangle(brsDarkBlue, 0, 0, 400, 400);<BR><BR> objGrx.FillEllipse(myLinearGradientBrush, 0, 0, 400, 400);<BR> <BR> objBmp.Save(Server.MapPath("test.wmf"), ImageFormat.Wmf);Bitmap objBmp = new Bitmap(400, 400);<BR> Graphics objGrx = Graphics.FromImage(objBmp);<BR><BR> //Brush For Background Rectangle<BR> Brush brsDarkBlue = new SolidBrush(System.Drawing.Color.FromArgb(51, 102, 153));<BR> <BR> //Create a Path for the PathGradientBrush<BR> GraphicsPath myPath = new GraphicsPath();<BR> //Path is Circle<BR> myPath.AddEllipse(0, 0, 400, 400);<BR> //PathGradientBrush Constructor with Specified Path<BR> PathGradientBrush pthGrBrush = new PathGradientBrush(myPath);<BR> //Set the Center Color<BR> pthGrBrush.CenterColor = Color.White;<BR> //Color Array to Fade to<BR> Color[] arrColor = new Color[1] {Color.FromArgb(51, 102, 153)};<BR> pthGrBrush.SurroundColors = arrColor;<BR><BR> //Background Rectangle<BR> objGrx.FillRectangle(brsDarkBlue, 0, 0, 400, 400);<BR> //Circle with Radial Gradient Fill<BR> objGrx.FillEllipse(pthGrBrush, 0, 0, 400, 400);<BR><BR> //Save Image<BR> objBmp.Save(Server.MapPath("test.wmf"), ImageFormat.Wmf);
 
Back
Top