Round Corner generator

by OfirYaron 2/14/2009 2:46:00 AM
This is a little function I've built that return an image of a round corner - by selecting the border color and the fill color, the nice thing is you can use it to generate a rounded corner on the fly in your web site, it's pretty fast!

public static Bitmap RoundedCorner(ContentAlignment position ,int height, int width, Color border, Color fill)
{
    Bitmap myBmpImage = new Bitmap(1, 1);

    // Create the graphics object
    Graphics myGraphics = Graphics.FromImage(myBmpImage);
    myBmpImage = new Bitmap(myBmpImage, new Size(width, height));
    myGraphics = Graphics.FromImage(myBmpImage);

    float pX = 0;
    float pY = 0;

    if ((position == ContentAlignment.BottomLeft) || (position == ContentAlignment.BottomRight)) pY -= height;
    if ((position == ContentAlignment.BottomRight) || (position == ContentAlignment.TopRight)) pX -= width;

    // Set Background color
    myGraphics.Clear(Color.Transparent);
    myGraphics.SmoothingMode = SmoothingMode.HighQuality;
    myGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

     if (fill != null)     
        myGraphics.FillEllipse(new SolidBrush(fill), pX, pY, width * 2, height * 2);

    if (border != null)
        myGraphics.DrawEllipse(new Pen(border), pX, pY, width * 2, height * 2);

    myGraphics.Flush();
    return (myBmpImage);
}
 

Ill upload test project later on to show how it works - right now you can pretty much copy-paste it.

Cheers,

Ofir 

 

Currently rated 4.7 by 7 people

  • Currently 4.714286/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Related posts

Comments are closed

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent posts

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in