In photo editor screen , I have imageview and it has background image and on top of imageview I add elements like text (label), stickers(images) etc. , Now for the final image containing all elements added on imageview , I am getting image from below code

clipRect is rect for background image inside imageview, image is aspectfit in imageview

Below is code inside UIView extension which has function to generate image out of view.

self == uiview

```
                  let op_format = UIGraphicsImageRendererFormat()
        op_format.scale = 1.0
        let renderer = UIGraphicsImageRenderer(bounds: CGRect(origin: clipRect!.origin, size: outputSize), format: op_format)
        let originalBound = self.bounds
        self.bounds = CGRect(origin: clipRect!.origin, size: clipRect!.size)
        var finalImage = renderer.image { ctx in
            self.drawHierarchy(in: CGRect(origin: self.bounds.origin, size: outputSize), afterScreenUpdates: true)
        }
        self.bounds = CGRect(origin: originalBound.origin, size: originalBound.size)

```

Issue here is quality of final image quality is very poor as compared to original background image.