title: Image quality problems when UILabel is rescaled and rasterized
body: <p>I have some problems in rescaling the content of a <code>UILabel</code> object when it is stored as an image. Since the rendered image has to be bigger than the original <code>UILabel</code>, I have computed the scale <code>imageScale</code> needed to rescale the original image and saved it into a <code>CGSize</code> variable. In the following, I will explain the adopted (and failing) approaches.</p>
  
  <p><strong>Code used for rendering the image</strong></p>
  
  <p>The following code is used for rendering the extracted image on the canvas.</p>
  
  <pre><code>[labelImage drawInRect:CGRectMake(xCoordinate/imageScale.width,
                                    yCoordinate/imageScale.height,
                                    newSize.width,
                                    newSize.height)
                            blendMode:kCGBlendModeNormal alpha:0.8];
  </code></pre>
  
  <p>where the variable <code>newSize</code> is computed as follows: </p>
  
  <ul>
  <li><code>newSize.width = originalWidth/imageScale.width</code>; </li>
  <li><code>newSize.height = originalHeight/imageScale.height</code></li>
  </ul>
  
  <p><strong>Approach 1</strong></p>
  
  <p>I extracted the label using the following code:</p>
  
  <pre><code>UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
      [[label layer] renderInContext: UIGraphicsGetCurrentContext()];
      UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  </code></pre>
  
  <p>where <code>label</code> is the <code>UILabel</code> variable and <code>newSize</code> is the size that the rescaled image should have (see above for details).</p>
  
  <p>However, I obtain the following image, which is obviously failing, since the content is very little and not centered:</p>
  
  <p><img src="https://i.stack.imgur.com/Cu5nk.png" alt="enter image description here"></p>
  
  <p><strong>Approach 2</strong></p>
  
  <p>I extracted the label using the following code:</p>
  
  <pre><code>UIGraphicsBeginImageContextWithOptions([label bounds].size, NO, 0.0);
      [[label layer] renderInContext: UIGraphicsGetCurrentContext()];
      UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  </code></pre>
  
  <p>However, since I am using the original image size in order to extract the image, the effect I obtain is the following:</p>
  
  <p><img src="https://i.stack.imgur.com/mKHe3.png" alt="enter image description here"></p>
  
  <p>As you can notice, the text in the balloon has not a high resolution, and thus it is not visualized properly.</p>
  
  <p><strong>The question</strong></p>
  
  <p>How to correct one of the two approaches so as to visualize in high resolution the image?</p>