Created
November 30, 2011 18:03
-
-
Save mloenow/1410055 to your computer and use it in GitHub Desktop.
Background creation with CoreGraphics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Drawing; | |
| using MonoTouch.CoreGraphics; | |
| using MonoTouch.UIKit; | |
| namespace MonoTouch.Utils { | |
| public class Graphics { | |
| public static CGImage CreateBackground(float width, float height, float radius, CGColor color) { | |
| CGImage image = null; | |
| using (var context = new CGBitmapContext(null, (int)width, (int)height, 8, 0, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast)) { | |
| context.SetFillColor(color); | |
| context.MoveTo(0, radius); | |
| context.AddLineToPoint(0, height - radius); | |
| context.AddArc(radius, height - radius, radius, Convert.ToSingle(Math.PI), Convert.ToSingle(Math.PI / 2), true); | |
| context.AddLineToPoint(width - radius, height); | |
| context.AddArc(width - radius, height - radius, radius, Convert.ToSingle(Math.PI / 2), 0, true); | |
| context.AddLineToPoint(width, radius); | |
| context.AddArc(width - radius, radius, radius, 0, -Convert.ToSingle(Math.PI / 2), true); | |
| context.AddLineToPoint(radius, 0); | |
| context.AddArc(radius, radius, radius, -Convert.ToSingle(Math.PI / 2), Convert.ToSingle(Math.PI), true); | |
| context.FillPath(); | |
| image = context.ToImage(); | |
| } | |
| return image; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment