Closed GaneshManickam closed 6 years ago
Not sure if this is the same crash @GaneshManickam had. The crash happens at the following line in CGImage+IGRPhonoTweakExtension.swift: let result = context!.makeImage()!
Oct 26 23:00:10 ...
To recreate the crash, take a snapshot on your iPhone or simulator. The crash does not happen if it is a regular image.
So I set CGBITMAP_CONTEXT_LOG_ERRORS = 1 in env variable to get the details. I hope it helps:
Oct 26 23:12:02 ...
Same here - seems this library is becoming stale. Hope we can fix.
I'm using below code to avoid crash but still this library not support panorama image crop. Use below code to avoid crash
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
print("didFinishPickingMediaWithInfo")
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
picker.dismiss(animated: false, completion: { () -> Void in
let smallest = min(pickedImage.size.width, pickedImage.size.height)
let largest = max(pickedImage.size.width, pickedImage.size.height)
let ratio = largest/smallest
if (ratio >= CGFloat(2/1)) || (ratio >= CGFloat(4/1)) || (ratio >= CGFloat(10/1)) {
// it is probably a panorama
print( "Panorama can't set for profile image")
} else {
//Pass image to cropper here
}
})
}
}
Because library using the original image width as the output image width.
E.x: 100000x500 -> 1:1 crop -> 100000x100000 (memory issue crash)
Simple fix:
CGImage+IGRPhonoTweakExtension.swift
New param: zoomScale
func transformedImage(_ transform: CGAffineTransform, zoomScale: CGFloat, sourceSize: CGSize, cropSize: CGSize, imageViewSize: CGSize) -> CGImage { let expectedWidth = floor(sourceSize.width / imageViewSize.width * cropSize.width) / zoomScale let expectedHeight = floor(sourceSize.height / imageViewSize.height * cropSize.height) / zoomScale let outputSize = CGSize(width: expectedWidth, height: expectedHeight) let bitmapBytesPerRow = 0
IGRPhotoTweakViewController.swift Line 126, replace the function call
let imageRef = fixedImage.transformedImage(transform, zoomScale: self.photoView.scrollView.zoomScale, sourceSize: self.image.size, cropSize: self.photoView.cropView.frame.size, imageViewSize: self.photoView.photoContentView.bounds.size)
@ykying Thank You!
Merged fix
App getting crashed while cropping panorama image