title: Rendering Emoji(String) to highest resolution image possible in iOS using extension/UIgraphicscontext
body: <p>So it is known that apple's the images backing Emoji in unicode can be extracted at a resolution as high as 160x160 pixels. There is a tool available that can do this on OS X by pulling the data out of "apple color emoji" font here: <a href="https://github.com/tmm1/emoji-extractor" rel="nofollow noreferrer">https://github.com/tmm1/emoji-extractor</a></p>
  
  <p>I am interested in extracting/utilizing apple's Emoji images in a similar way on iOS, I found the following solution and really like the implementation here: <a href="https://stackoverflow.com/a/38809531/4556704">https://stackoverflow.com/a/38809531/4556704</a></p>
  
  <pre><code>extension String {
  func image() -&gt; UIImage {
      let size = CGSize(width: 30, height: 35)
      UIGraphicsBeginImageContextWithOptions(size, false, 0);
      UIColor.whiteColor().set()
      let rect = CGRect(origin: CGPointZero, size: size)
      UIRectFill(CGRect(origin: CGPointZero, size: size))
      (self as NSString).drawInRect(rect, withAttributes: [NSFontAttributeName: UIFont.systemFontOfSize(30)])
      let image = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
      return image
  }
  
  }
  </code></pre>
  
  <p>There is a problem, however, that I am running into with this implementation. If I use the string extension above, it is obvious to me that the resulting image is not 160x160 px in resolution. What I mean by that is, I am unable to produce an image of comparable quality to, say, if I were to include a 160x160 image in my project's assets.</p>
  
  <p>What is the reasoning for this, and can I solve this problem without importing upwards of 1700 emoji images to my project? I figure that the font on iOS must still contain the data necessary to produce 160x160 image samples. The String extension is ideal as it allows me to reference the emoji characters more freely than if I were to simple import all these images. </p>
  
  <p>I figure this may require some low level code that could be way more trouble than it's worth, but I really would love to know more about the root of this issue and possible fixes. I'm sure this is attributed to apple not rendering the emoji at a level higher than necessary, but surely there is some way to override this. Also I am aware that there are other high resolution Emoji image sets, this question is not about that.</p>
  
  <p>edit:
  <a href="https://i.stack.imgur.com/JRleI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JRleI.png" alt="mismatched resolutions"></a></p>
  
  <p>edit 10/18/16:
  I've come to the conclusion that the issue can be attributed to the fact that the source image being sampled is not of the highest resolution that is assumed to be possible. It seems that the emoji is not being rendered at resolutions higher than 48x48 px, when it has been demonstrated that the emoji images can be rendered up to 160x160 px on OS X, and can be ripped from "Apple Color Emoji.ttf/.ttc" at 160x160 px. I am not sure if there even is a possible solution to this issue, as it seems like a hard limit imposed by how iOS uses unicode character codes that map to png image data.</p>