Skip to content

Commit

Permalink
fix: use round() instead of floor() for output image size
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingtao Guo committed Aug 6, 2022
1 parent 560e272 commit b3feefa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 0 additions & 3 deletions Example/EmbeddedCropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ extension EmbeddedCropViewController: CropViewControllerDelegate {
}

func cropViewControllerDidEndResize(_ cropViewController: CropViewController, original: UIImage, cropInfo: CropInfo) {
// cropViewController.getExpectedCropImageSize() uses floor() to get integer image width and height
// If you use this size to check if it is less than an upper limit, you may need to add 1 to width and height
// to make sure the size is valid
let size = cropViewController.getExpectedCropImageSize()
self.resolutionLabel.text = "\(Int(size.width)) x \(Int(size.height)) pixels"
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Mantis/Extensions/UIImageExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ extension UIImage {
let cropSize = cropInfo.cropSize
let imageViewSize = cropInfo.imageViewSize

let expectedWidth = floor(size.width / imageViewSize.width * cropSize.width) / zoomScale
let expectedHeight = floor(size.height / imageViewSize.height * cropSize.height) / zoomScale
let expectedWidth = round(size.width / imageViewSize.width * cropSize.width) / zoomScale
let expectedHeight = round(size.height / imageViewSize.height * cropSize.height) / zoomScale

return CGSize(width: expectedWidth, height: expectedHeight)
}
Expand Down

0 comments on commit b3feefa

Please sign in to comment.