Skip to content

Commit

Permalink
fix #830
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Aug 25, 2023
1 parent 771b6a6 commit 974e91d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Please fill in the detailed description of the issue (full output of any stack t

#### Info
ZLPhotoBrowser version: e.g. 4.4.3.2
Device: e.g. iPhone X
Device version: e.g. iOS 14.0
Xcode version: e.g. Xcode 12.0
Device: e.g. iPhone 14 Pro
Device version: e.g. iOS 16.0
Xcode version: e.g. Xcode 14.0

#### Configuration code of `ZLPhotoConfiguration`

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If you only want to use the image edit feature, please move to [ZLImageEditor](h
### Requirements
* iOS 10.0
* Swift 5.x
* Xcode 12.x
* Xcode 13.x

### Usage
- Preview selection
Expand Down
28 changes: 22 additions & 6 deletions Sources/Camera/ZLCustomCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,7 @@ open class ZLCustomCamera: UIViewController {
// 相机画面输入流
self.videoInput = input

let preset = cameraConfig.sessionPreset.avSessionPreset
if self.session.canSetSessionPreset(preset) {
self.session.sessionPreset = preset
} else {
self.session.sessionPreset = .photo
}
self.refreshSessionPreset(device: camera)

let movieFileOutput = AVCaptureMovieFileOutput()
// 解决视频录制超过10s没有声音的bug
Expand Down Expand Up @@ -569,6 +564,23 @@ open class ZLCustomCamera: UIViewController {
}
}

private func refreshSessionPreset(device: AVCaptureDevice) {
func setSessionPreset(_ preset: AVCaptureSession.Preset) {
guard session.sessionPreset != preset else {
return
}

session.sessionPreset = preset
}

let preset = cameraConfig.sessionPreset.avSessionPreset
if device.supportsSessionPreset(preset), session.canSetSessionPreset(preset) {
setSessionPreset(preset)
} else {
setSessionPreset(.photo)
}
}

private func getCamera(position: AVCaptureDevice.Position) -> AVCaptureDevice? {
let devices = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, position: position).devices
for device in devices {
Expand Down Expand Up @@ -796,12 +808,16 @@ open class ZLCustomCamera: UIViewController {

if let newVideoInput = newVideoInput {
self.session.beginConfiguration()

self.refreshSessionPreset(device: newVideoInput.device)

self.session.removeInput(currInput)

if self.session.canAddInput(newVideoInput) {
self.session.addInput(newVideoInput)
self.videoInput = newVideoInput
} else {
self.refreshSessionPreset(device: currInput.device)
self.session.addInput(currInput)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Edit/ZLEditImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ open class ZLEditImageViewController: UIViewController {
size.width *= toImageScale
size.height *= toImageScale

UIGraphicsBeginImageContextWithOptions(size, false, editImage.scale)
UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
let context = UIGraphicsGetCurrentContext()
// 去掉锯齿
context?.setAllowsAntialiasing(true)
Expand Down
3 changes: 3 additions & 0 deletions Sources/General/ZLCameraConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public extension ZLCameraConfiguration {
return .hd1280x720
case .hd1920x1080:
return .hd1920x1080
case .hd4K3840x2160:
return .hd4K3840x2160
case .photo:
return .photo
}
Expand All @@ -128,6 +130,7 @@ public extension ZLCameraConfiguration {
case vga640x480
case hd1280x720
case hd1920x1080
case hd4K3840x2160
case photo
}

Expand Down
1 change: 1 addition & 0 deletions Sources/General/ZLPhotoPreviewSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ public class ZLPhotoPreviewSheet: UIView {

if config.callbackDirectlyAfterTakingPhoto {
requestSelectPhoto()
return
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/General/ZLThumbnailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ class ZLThumbnailViewController: UIViewController {

if config.callbackDirectlyAfterTakingPhoto {
doneBtnClick()
return
}
}
}
Expand Down

0 comments on commit 974e91d

Please sign in to comment.