diff --git a/YOLO/Info.plist b/YOLO/Info.plist
index a7022ec..1b8bfb4 100644
--- a/YOLO/Info.plist
+++ b/YOLO/Info.plist
@@ -21,7 +21,7 @@
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
- 25
+ 26
ITSAppUsesNonExemptEncryption
LSRequiresIPhoneOS
diff --git a/YOLO/ViewController.swift b/YOLO/ViewController.swift
index 840d91d..3c1bad2 100644
--- a/YOLO/ViewController.swift
+++ b/YOLO/ViewController.swift
@@ -36,6 +36,7 @@ class ViewController: UIViewController {
@IBOutlet weak var labelVersion: UILabel!
@IBOutlet weak var labelSlider: UILabel!
@IBOutlet weak var labelSliderConf: UILabel!
+ var screenshotImageView: UIImageView?
@IBOutlet weak var labelSliderConfLandScape: UILabel!
@IBOutlet weak var labelSliderIoU: UILabel!
@IBOutlet weak var labelSliderIoULandScape: UILabel!
@@ -403,7 +404,6 @@ class ViewController: UIViewController {
print("no file written")
}
}
-
// Reading
// do {let text2 = try String(contentsOf: fileURL, encoding: .utf8)} catch {/* error handling here */}
}
@@ -614,6 +614,46 @@ class ViewController: UIViewController {
default: break
}
} // Pinch to Zoom End --------------------------------------------------------------------------------------------
+
+ func showShareAlert(image: UIImage) {
+ let alertController = UIAlertController(
+ title: "Do you want to share this image?", message: nil, preferredStyle: .alert)
+
+ let shareAction = UIAlertAction(title: "OK", style: .default) { _ in
+ self.shareImage(image: image)
+ }
+
+ let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { _ in
+ self.hideScreenshotImageView()
+ }
+
+ alertController.addAction(shareAction)
+ alertController.addAction(cancelAction)
+
+ if let popoverController = alertController.popoverPresentationController {
+ popoverController.sourceView = self.view
+ popoverController.sourceRect = CGRect(
+ x: self.view.bounds.midX, y: self.view.bounds.maxY - 100, width: 0, height: 0)
+ popoverController.permittedArrowDirections = []
+ }
+
+ present(alertController, animated: true, completion: nil)
+ }
+
+ func shareImage(image: UIImage) {
+ let activityViewController = UIActivityViewController(
+ activityItems: [image], applicationActivities: nil)
+ activityViewController.popoverPresentationController?.sourceView = self.View0
+ self.present(activityViewController, animated: true) {
+ self.hideScreenshotImageView()
+ }
+ }
+
+ func hideScreenshotImageView() {
+ self.screenshotImageView?.removeFromSuperview()
+ self.screenshotImageView = nil
+ }
+ // ------------------------------------------------------------------------------------------
} // ViewController class End
extension ViewController: VideoCaptureDelegate {
@@ -635,7 +675,7 @@ extension ViewController: AVCapturePhotoCaptureDelegate {
let cgImageRef: CGImage! = CGImage(
jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true,
intent: .defaultIntent)
- var orientation = CGImagePropertyOrientation.right
+ var orientation = UIImage.Orientation.right
switch UIDevice.current.orientation {
case .landscapeLeft:
orientation = .up
@@ -644,16 +684,13 @@ extension ViewController: AVCapturePhotoCaptureDelegate {
default:
break
}
- var image = UIImage(cgImage: cgImageRef, scale: 0.5, orientation: .right)
- if let orientedCIImage = CIImage(image: image)?.oriented(orientation),
- let cgImage = CIContext().createCGImage(orientedCIImage, from: orientedCIImage.extent)
- {
- image = UIImage(cgImage: cgImage)
- }
+ var image = UIImage(cgImage: cgImageRef, scale: 0.5, orientation: orientation)
let imageView = UIImageView(image: image)
imageView.contentMode = .scaleAspectFill
imageView.frame = videoPreview.frame
let imageLayer = imageView.layer
+ var sublayers = videoPreview.layer.sublayers ?? []
+ let insertIndex = max(sublayers.count - 1, 0)
videoPreview.layer.insertSublayer(imageLayer, above: videoCapture.previewLayer)
let bounds = UIScreen.main.bounds
@@ -662,10 +699,23 @@ extension ViewController: AVCapturePhotoCaptureDelegate {
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
imageLayer.removeFromSuperlayer()
- let activityViewController = UIActivityViewController(
- activityItems: [img!], applicationActivities: nil)
- activityViewController.popoverPresentationController?.sourceView = self.View0
- self.present(activityViewController, animated: true, completion: nil)
+
+ let screenshotImageView = UIImageView(image: img)
+ screenshotImageView.frame = view.bounds
+ screenshotImageView.contentMode = .scaleAspectFit
+ view.addSubview(screenshotImageView)
+ self.screenshotImageView = screenshotImageView
+
+ UIView.animate(
+ withDuration: 0.3,
+ animations: {
+ screenshotImageView.frame = CGRect(
+ x: 20, y: 100, width: self.view.bounds.width - 40, height: self.view.bounds.height - 200
+ )
+ }
+ ) { _ in
+ self.showShareAlert(image: img!)
+ }
//
// // Save to camera roll
// UIImageWriteToSavedPhotosAlbum(img!, nil, nil, nil);