marinofaggiana 6 年之前
父節點
當前提交
4a43a26cfa

+ 2 - 0
iOSClient/Imagemeter/IMImagemeter.swift

@@ -183,6 +183,8 @@ class IMImagemeterCodable: NSObject {
             return decode
             
         } catch let error {
+            
+            print("Serious internal error in decoding metadata ("+error.localizedDescription+")")
             return nil
         }
     }

+ 3 - 2
iOSClient/Viewer/NCViewerImagemeter.storyboard

@@ -19,9 +19,9 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="kz9-lQ-2Uc">
-                                <rect key="frame" x="0.0" y="64" width="375" height="128"/>
+                                <rect key="frame" x="0.0" y="64" width="375" height="256"/>
                                 <constraints>
-                                    <constraint firstAttribute="height" constant="128" id="QfZ-vy-737"/>
+                                    <constraint firstAttribute="height" constant="256" id="QfZ-vy-737"/>
                                 </constraints>
                             </imageView>
                         </subviews>
@@ -36,6 +36,7 @@
                     <navigationItem key="navigationItem" id="ZuV-mh-zPX"/>
                     <connections>
                         <outlet property="img" destination="kz9-lQ-2Uc" id="r2x-XE-2Nf"/>
+                        <outlet property="imgHeightConstraint" destination="QfZ-vy-737" id="CZu-I3-wwo"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="ISU-dv-V7S" userLabel="First Responder" sceneMemberID="firstResponder"/>

+ 24 - 6
iOSClient/Viewer/NCViewerImagemeter.swift

@@ -26,10 +26,12 @@ import Foundation
 class NCViewerImagemeter: UIViewController {
     
     @IBOutlet weak var img: UIImageView!
+    @IBOutlet weak var imgHeightConstraint: NSLayoutConstraint!
     
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private var nameArchiveImagemeter: String = ""
     private var pathArchiveImagemeter: String = ""
+    private var annotation: IMImagemeterCodable.imagemeterAnnotation?
     var metadata: tableMetadata?
     
 
@@ -58,9 +60,8 @@ class NCViewerImagemeter: UIViewController {
             let annoData = try Data(contentsOf: annoPath, options: .mappedIfSafe)
             if let annotation = IMImagemeterCodable.sharedInstance.decoderAnnotetion(annoData) {
                 
-                if let thumbnailsFilename = annotation.thumbnails.first?.filename {
-                    img.image = UIImage(contentsOfFile: pathArchiveImagemeter + "/" + thumbnailsFilename)
-                }
+                self.annotation = annotation
+                imgThumbnails()
                 
             } else {
                 appDelegate.messageNotification("_error_", description: "_error_decompressing_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
@@ -69,12 +70,29 @@ class NCViewerImagemeter: UIViewController {
         } catch {
             print("error:\(error)")
         }
-        
-        
-        //img.image = UIImage(contentsOfFile: imgPath)
     }
     
     @objc func close() {
         self.dismiss(animated: true, completion: nil)
     }
+    
+    func imgThumbnails() {
+        
+        guard let annotation = self.annotation else {
+            return
+        }
+        
+        if let thumbnailsFilename = annotation.thumbnails.first?.filename {
+            if let thumbnailsWidth = annotation.thumbnails.first?.width {
+                if let thumbnailsHeight = annotation.thumbnails.first?.height {
+                    
+                    let ratio = Float(thumbnailsWidth) / Float(thumbnailsHeight)
+                    let imageWidth = self.view.bounds.size.width
+                    
+                    imgHeightConstraint.constant = CGFloat((Float(imageWidth) / ratio))
+                    img.image = UIImage(contentsOfFile: pathArchiveImagemeter + "/" + thumbnailsFilename)
+                }
+            }
+        }
+    }
 }