Skip to content

Commit

Permalink
Optimised and cleaned up iOS cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Salmon authored and SergeShkurko committed Oct 31, 2019
1 parent 7ff9329 commit 659df31
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions packages/native_pdf_renderer/ios/Classes/document/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,21 @@ class Page {
context!.setFillColor(backgroundColor.cgColor)
context!.fill(pdfBBox)
context!.drawPDFPage(renderer)
let image = UIImage(cgImage: context!.makeImage()!)
var image = UIImage(cgImage: context!.makeImage()!)

if (crop != nil){
// Perform cropping in Core Graphics
let cutImageRef: CGImage = (image.cgImage?.cropping(to:crop!))!
let croppedImage: UIImage = UIImage(cgImage: cutImageRef)
image = UIImage(cgImage: cutImageRef)
}

data = croppedImage.pngData() as Data?
switch(compressFormat) {
case CompressFormat.JPEG:
data = croppedImage.jpegData(compressionQuality: 1.0) as Data?
break;
case CompressFormat.PNG:
data = croppedImage.pngData() as Data?
break;
}
} else {
switch(compressFormat) {
case CompressFormat.JPEG:
data = image.jpegData(compressionQuality: 1.0) as Data?
break;
case CompressFormat.PNG:
data = image.pngData() as Data?
break;
}
switch(compressFormat) {
case CompressFormat.JPEG:
data = image.jpegData(compressionQuality: 1.0) as Data?
break;
case CompressFormat.PNG:
data = image.pngData() as Data?
break;
}

success = true
Expand Down

0 comments on commit 659df31

Please sign in to comment.