Created
July 10, 2012 22:48
-
-
Save jfoshee/3086735 to your computer and use it in GitHub Desktop.
Convert text string to UIImage in MonoTouch
This file contains 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
static public UIImage StringToImage(string s, float fontSize) | |
{ | |
return StringToImage(s, UIFont.FromName("Helvetica", fontSize)); | |
} | |
static public UIImage StringToImage(string s, UIFont font) | |
{ | |
var ns = new NSString(s); | |
var size = ns.StringSize(font); | |
UIGraphics.BeginImageContext(size); | |
ns.DrawString(PointF.Empty, font); | |
var image = UIGraphics.GetImageFromCurrentImageContext(); | |
UIGraphics.EndImageContext(); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment