Переглянути джерело

优化获取相册图片时的内存占用

zhongbaojian 5 роки тому
батько
коміт
cf035c8c94

+ 3 - 3
Podfile.lock

@@ -46,7 +46,7 @@ PODS:
     - WCDBOptimizedSQLCipher (~> 1.2.0)
   - SSZipArchive (2.2.2)
   - SVProgressHUD (2.2.5)
-  - TZImagePicker (1.0.0)
+  - TZImagePicker (1.0.1)
   - UMCAnalytics (6.0.5):
     - UMCCommon
   - UMCCommon (2.1.1)
@@ -161,7 +161,7 @@ CHECKOUT OPTIONS:
     :commit: 08b2719dc65f20f0a66b92d589278b77e94eabeb
     :git: http://svn.ouj.com:3000/duowan_iOS/OJASwiftKit.git
   TZImagePicker:
-    :commit: 4d41a59acd487cef15128371182193f790ecfb92
+    :commit: 76d5018956cdd774d8b4524b10d4d1d1049c5f70
     :git: http://svn.ouj.com:3000/duowan_iOS/TZImagePicker.git
   YYKit:
     :commit: 1f148f9ba4948659837187a2fec09686fe576773
@@ -202,7 +202,7 @@ SPEC CHECKSUMS:
   SQLiteRepairKit: 35aaae5a8838adb85f5b1eb4d796055be6060a4b
   SSZipArchive: fa16b8cc4cdeceb698e5e5d9f67e9558532fbf23
   SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
-  TZImagePicker: b296bc76c8971800da13ded82edf3e1a19fd99f4
+  TZImagePicker: c5dd2ab1c7b1d9237eeff75350d3c6920dd9cf29
   UMCAnalytics: 045be2cd1ec05aa95ad62405a850757f932e2d59
   UMCCommon: 971f324a5a99c9d662ae040a815e7e3d7ef8b2a8
   WCDB.swift: 05d509d7a0e60fb6e11c34eb7e4027c0fab5849f

+ 1 - 1
SuperShow/OJAGPUImageDecoder/OJAAssetReader.swift

@@ -89,7 +89,7 @@ class OJAAssetReader: NSObject {
         
         let success = reader.startReading()
         if !success {
-            NSLog("reading error: \(self.urlAsset)")
+            NSLog("reading error: \(String(describing: reader.error)) \n ***\(self.urlAsset)")
         }
         self.lock.unlock()
         

+ 17 - 18
SuperShow/Tool/WSSImagePickerController.swift

@@ -457,23 +457,7 @@ extension WSSImagePickerController: TZImagePickerControllerDelegate {
             }
 
             if let manager = TZImageManager.default() {
-                assetRequestID = manager.getOriginalPhoto(with: asset, progressHandler: { [weak self] percent, err, _, _ in
-                    if self?.isPageShowing == true {
-                        DispatchQueue.main.async(execute: {
-                            if percent > 0.0 && percent < 1.0 {
-                                showProgressHud(progress: Float(percent), status: "iCloud下载中")
-                            } else {
-                                hideHud()
-                            }
-
-                            if err != nil {
-                                showHud(withOnlyText: err!.localizedDescription)
-                            }
-                        })
-                    }
-                }, newCompletion: { [weak self] (originalImage: UIImage?, _: [AnyHashable: Any]?, isDegraded: Bool) in
-
-//                    WSSLog("$$$$: \(originalImage) +++ \(isDegraded)")
+                assetRequestID = manager.getPhotoWith(asset, photoWidth: kOJSScreenWidth, completion: { [weak self] (originalImage: UIImage?, _: [AnyHashable: Any]?, isDegraded: Bool) in
 
                     if isDegraded == false, let img = originalImage {
                         let model = SelectedModel(cover: coverImage, image: img, original: asset)
@@ -490,7 +474,22 @@ extension WSSImagePickerController: TZImagePickerControllerDelegate {
                         }
                     }
 
-                })
+                }, progressHandler: { [weak self] percent, err, _, _ in
+                    if self?.isPageShowing == true {
+                        DispatchQueue.main.async(execute: {
+                            if percent > 0.0 && percent < 1.0 {
+                                showProgressHud(progress: Float(percent), status: "iCloud下载中")
+                            } else {
+                                hideHud()
+                            }
+
+                            if err != nil {
+                                showHud(withOnlyText: err!.localizedDescription)
+                            }
+                        })
+                    }
+
+                }, networkAccessAllowed: true)
             }
         }
     }

+ 9 - 0
SuperShow/UI/ResourcePicker/WSSCreativeTemplateResourcePickerViewController.swift

@@ -131,6 +131,15 @@ class WSSCreativeTemplateResourcePickerViewController: WSSResourcePickerControll
         return msg
     }
 
+    override func selectPhotoModel(_ model: TZAssetModel, cover: UIImage) {
+        var defaultSize: CGSize = WSSMediaOperationTool.EXPORT_DEFAULT_SIZE
+        if let em = self.editModel, em.templateWidth > 0 && em.templateHeight > 0 {
+            defaultSize = CGSize(width: em.templateWidth, height: em.templateHeight)
+        }
+
+        loadPhotoAsset(coverImage: cover, phAsset: model.asset, targetWidth: defaultSize.width)
+    }
+
     override func successSelectOneResource() {
         if maxResourcesCount == 1 && selectedCreativeModels.count == 1 {
             // 当需要选择的素材为1个的时候,选择完素材就跳转页面

+ 38 - 37
SuperShow/UI/ResourcePicker/WSSResourcePickerController.swift

@@ -466,6 +466,44 @@ class WSSResourcePickerController: MTViewController {
         loadPhotoAsset(coverImage: cover, phAsset: model.asset)
     }
 
+    func loadPhotoAsset(coverImage: UIImage, phAsset: PHAsset, targetWidth: CGFloat = kOJSScreenWidth) {
+        if let manager = TZImageManager.default() {
+            assetRequestID = manager.getPhotoWith(phAsset, photoWidth: targetWidth, completion: { [weak self] (originalImage: UIImage?, _: [AnyHashable: Any]?, isDegraded: Bool) in
+                guard let nextIndex = self?.getNextNeedSelectIndex(),
+                    let nextModel = self?.selectModels.safeObject(atIndex: nextIndex) else { return }
+                self?.assetRequestID = 0
+                if isDegraded == false, let img = originalImage {
+                    nextModel.setPhotoAsset(cover: coverImage, image: img, original: phAsset)
+                    self?.refreshState()
+                    self?.successSelectOneResource()
+
+                } else {
+                    if self?.isPageShowing == true {
+                        if originalImage == nil {
+                            showHud(withOnlyText: "读取资源失败,稍后重试")
+                        }
+                    }
+                }
+
+            }, progressHandler: { [weak self] percent, err, _, _ in
+                if self?.isPageShowing == true {
+                    DispatchQueue.main.async(execute: {
+                        if percent > 0.0 && percent < 1.0 {
+                            showProgressHud(progress: Float(percent), status: "iCloud下载中")
+                        } else {
+                            hideHud()
+                        }
+
+                        if err != nil {
+                            showHud(withOnlyText: err!.localizedDescription)
+                        }
+                    })
+                }
+
+            }, networkAccessAllowed: true)
+        }
+    }
+
     /// 成功选择一个资源:视频或者图片
     func successSelectOneResource() {
         //
@@ -651,43 +689,6 @@ private extension WSSResourcePickerController {
         })
     }
 
-    func loadPhotoAsset(coverImage: UIImage, phAsset: PHAsset) {
-        if let manager = TZImageManager.default() {
-            assetRequestID = manager.getOriginalPhoto(with: phAsset, progressHandler: { [weak self] percent, err, _, _ in
-                if self?.isPageShowing == true {
-                    DispatchQueue.main.async(execute: {
-                        if percent > 0.0 && percent < 1.0 {
-                            showProgressHud(progress: Float(percent), status: "iCloud下载中")
-                        } else {
-                            hideHud()
-                        }
-
-                        if err != nil {
-                            showHud(withOnlyText: err!.localizedDescription)
-                        }
-                    })
-                }
-            }, newCompletion: { [weak self] (originalImage: UIImage?, _: [AnyHashable: Any]?, isDegraded: Bool) in
-                guard let nextIndex = self?.getNextNeedSelectIndex(),
-                    let nextModel = self?.selectModels.safeObject(atIndex: nextIndex) else { return }
-                self?.assetRequestID = 0
-                if isDegraded == false, let img = originalImage {
-                    nextModel.setPhotoAsset(cover: coverImage, image: img, original: phAsset)
-                    self?.refreshState()
-                    self?.successSelectOneResource()
-
-                } else {
-                    if self?.isPageShowing == true {
-                        if originalImage == nil {
-                            showHud(withOnlyText: "读取资源失败,稍后重试")
-                        }
-                    }
-                }
-
-            })
-        }
-    }
-
     func refreshConfirmBarItemState() {
         topTipLabel.text = topTipMessage()
         /// 大于一个视频,才可以进行下一步