0

enter image description hereenter image description hereIn my IOS App Code I am taking screenshot of UIimageView but when I take it it's not taken properly by following code.

func captureView() -> UIImage {
//        let rect: CGRect = self.imageView.bounds

        UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, 0.0)//add this line

        let context: CGContextRef = UIGraphicsGetCurrentContext()!
        self.view.layer.renderInContext(context)
        let img: UIImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return img
    }

I want the exect screen shot of the image in imageView because there are more images on it. Kindly suggest me proper code for getting exact UIImageView Screenshot

JAck
  • 854
  • 9
  • 18

1 Answers1

0

How about you add UIScreen.mainScreen().scale instead of 0.0 in UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)

func captureView() -> UIImage {
            UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
            drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
            let img = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return img!
        }
Rurouni
  • 963
  • 10
  • 31