Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following code creates a snapshot of the enclosing view (superview of <code>faceImageView</code> with <code>clipsToBounds</code> set to <code>YES</code>) using a calculated scale factor.</p> <p>It assumes that the content mode of faceImageView is <code>UIViewContentModeScaleAspectFit</code> and that the frame of faceImageView is set to the enclosingView's bounds.</p> <pre><code>- (UIImage *)captureView { float imageScale = sqrtf(powf(faceImageView.transform.a, 2.f) + powf(faceImageView.transform.c, 2.f)); CGFloat widthScale = faceImageView.bounds.size.width / faceImageView.image.size.width; CGFloat heightScale = faceImageView.bounds.size.height / faceImageView.image.size.height; float contentScale = MIN(widthScale, heightScale); float effectiveScale = imageScale * contentScale; CGSize captureSize = CGSizeMake(enclosingView.bounds.size.width / effectiveScale, enclosingView.bounds.size.height / effectiveScale); NSLog(@"effectiveScale = %0.2f, captureSize = %@", effectiveScale, NSStringFromCGSize(captureSize)); UIGraphicsBeginImageContextWithOptions(captureSize, YES, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextScaleCTM(context, 1/effectiveScale, 1/effectiveScale); [enclosingView.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } </code></pre> <p>Depending on the current transform the resulting image will have a different size. For example when you zoom in, the size gets smaller. You can also set <code>effectiveScale</code> to a constant value in order to get an image with a constant size.</p> <p>Your gesture recognizer code does not limit the scale factor, i.e. you can zoom out/in without being limited. That can be very dangerous! My capture method can output really large images when you've zoomed out very much.</p> <p>If you have zoomed out the background of the captured image will be black. If you want it to be transparent, you must set the opaque-parameter of <code>UIGraphicsBeginImageContextWithOptions</code> to <code>NO</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload