Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Added rectangular and square cropping frame support. #220

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Added rectangular and square cropping frame support. #220

wants to merge 2 commits into from

Conversation

npu3pak
Copy link

@npu3pak npu3pak commented Sep 12, 2017

In my project, you need to crop the square areas of the images. I think this is a fairly frequent use case.
Since there are now 3 cropping modes (none, square, rectangle), I replaced the allowResizing parameter with the resizingMode enumeration.

@Cyclic
Copy link

Cyclic commented Oct 4, 2017

@AlexLittlejohn it looks like there are some conflicts here. There are some other items that I am working on that I will eventually cherry pick into other branches (data return type, etc.) I am also running into a threading issue with this line AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer) -- and I would like to include EXIF output to figure out which thread in my app is clobbering this call. For some reason, the try? of this call was deprecated in iOS 10 and now exceptions in the jpeg data are thrown (see below).

If you have any insight into this, that would be very much appreciated. It seems like dumping out the EXIF header should shed light on the situation:

Fatal Exception: NSInvalidArgumentException
*** +[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] Not a jpeg sample buffer.

`Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x189866fe0 __exceptionPreprocess
1 libobjc.A.dylib 0x1882c8538 objc_exception_throw
2 AVFoundation 0x1912ba11c +[AVCaptureStillImageOutput jpegStillImageNSDataRepresentationForSurface:size:metadata:]
3 ALCameraViewController 0x10066277c specialized closure #1 in takePhoto(:videoOrientation:cameraPosition:cropSize:outputScale:completion:) (CameraShot.swift:26)
4 ALCameraViewController 0x10066253c closure #1 in takePhoto(
:videoOrientation:cameraPosition:cropSize:outputScale:completion:) (CameraShot.swift)
5 ALCameraViewController 0x100662be8 thunk for @callee_owned (@owned CMSampleBuffer?, @owned Error?) -> () (CameraView.swift)
6 AVFoundation 0x1912b9afc -[AVCaptureStillImageOutput handleNotification:payload:]
7 CoreFoundation 0x18981530c CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK
8 CoreFoundation 0x189814b28 __CFRunLoopDoBlocks
9 CoreFoundation 0x189812e1c __CFRunLoopRun
10 CoreFoundation 0x189742da4 CFRunLoopRunSpecific
11 GraphicsServices 0x18b1ad074 GSEventRunModal
12 UIKit 0x18f9fdc9c UIApplicationMain

guard let buffer = buffer, let exifAttachments = CMGetAttachment(buffer, kCGImagePropertyExifDictionary, nil), let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer), var image = UIImage(data: imageData), let cgImage = image.cgImage else { completion(nil, nil) return }

@daviskoh
Copy link

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants