[ad_1]
I’m engaged on annotate a picture to an present PDFView.
That is my present state:
And beneath is my desired state:
In a single sentence, I wish to obtain:
- a rounded corder of my picture annotation
- picture must also keep the unique facet ratio
I’ve tried and searched many sources however none of them works.
Under is my present code:
class PDFImageAnnotation: PDFAnnotation {
var picture: UIImage?
comfort init(_ picture: UIImage?, bounds: CGRect, properties: [AnyHashable : Any]?) {
self.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties)
self.picture = picture
}
override func draw(with field: PDFDisplayBox, in context: CGContext) {
tremendous.draw(with: field, in: context)
// Drawing the picture inside the annotation's bounds.
guard let cgImage = picture?.cgImage else { return }
context.draw(cgImage, in: bounds)
}
}
Implementation in ViewDidLoad:
if let picture = pet.image?.getImage() {
let imageAnnotation = PDFImageAnnotation(picture, bounds: CGRect(x: 80, y: 1100, width: 300, peak: 300), properties: nil)
pdfView.currentPage?.addAnnotation(imageAnnotation)
}
[ad_2]