我正在為現有的 PDFView 注釋影像。這是我目前的狀態:

下面是我想要的狀態:

一句話,我想實作:
- 我的影像注釋的圓形編碼器
- 影像還應該保持原始縱橫比,我已經嘗試并搜索了許多來源,但沒有一個有效。
以下是我目前的代碼:
class PDFImageAnnotation: PDFAnnotation {
var image: UIImage?
convenience init(_ image: UIImage?, bounds: CGRect, properties: [AnyHashable : Any]?) {
self.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties)
self.image = image
}
override func draw(with box: PDFDisplayBox, in context: CGContext) {
super.draw(with: box, in: context)
// Drawing the image within the annotation's bounds.
guard let cgImage = image?.cgImage else { return }
context.draw(cgImage, in: bounds)
}
}
ViewDidLoad 中的實作:
if let image = pet.picture?.getImage() {
let imageAnnotation = PDFImageAnnotation(image, bounds: CGRect(x: 80, y: 1100, width: 300, height: 300), properties: nil)
pdfView.currentPage?.addAnnotation(imageAnnotation)
}
任何建議都會有所幫助,因為我現在處于死胡同,非常感謝!
uj5u.com熱心網友回復:
好的,我想通了,原來我應該先將影像剪裁成四舍五入格式,然后使用此擴展名將其注釋到 PDF:https : //stackoverflow.com/a/64981764/11079192
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/369656.html
標籤:ios 迅速 代码 ios-pdfkit 苹果-pdfkit
