Skip to content

Instantly share code, notes, and snippets.

@jfoshee
Created July 10, 2012 22:48
Show Gist options
  • Save jfoshee/3086735 to your computer and use it in GitHub Desktop.
Save jfoshee/3086735 to your computer and use it in GitHub Desktop.
Convert text string to UIImage in MonoTouch
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