Przeglądaj źródła

Merge branch 'master' of https://git.yishihui.com/iOS/BFFramework

* 'master' of https://git.yishihui.com/iOS/BFFramework:
  支持添加data 方式初始化图片和gif
  图片支持系统相册路径
harry 3 lat temu
rodzic
commit
6c62ccbd5b

+ 12 - 1
BFFramework/Classes/PQGPUImage/akfilters/PQGifFilter.swift

@@ -37,7 +37,18 @@ open class PQGifFilter: PQBaseFilter {
         var gifData: Data!
         autoreleasepool {
             do {
-                gifData = try Data(contentsOf: URL(fileURLWithPath: documensDirectory + (mSticker?.locationPath ?? "")))
+                
+                if(mSticker?.originalData != nil && (mSticker?.originalData?.count ?? 0) > 0){
+                    gifData = mSticker?.originalData
+                }else{
+                    var gifFilePath = (mSticker?.locationPath ?? "")
+                    if (!gifFilePath.contains("var/mobile/Media")) {
+                        gifFilePath = documensDirectory + gifFilePath
+                    }
+                    BFLog(message: "gifFilePath is \(gifFilePath)")
+                    gifData = try Data(contentsOf: URL(fileURLWithPath: gifFilePath))
+                }
+               
             } catch {
                 print("loading gif images file error")
                 return

+ 25 - 7
BFFramework/Classes/PQGPUImage/akfilters/PQImageFilter.swift

@@ -36,11 +36,24 @@ open class PQImageFilter: PQBaseFilter {
 
         mSticker = sticker
         stickerInfo = sticker
-        if mSticker!.locationPath.count == 0 {
-            BFLog(2, message: "图片数据为空,创建失败")
-            return
+
+        
+        if(sticker.originalData != nil && (sticker.originalData?.count ?? 0) > 0){
+            newImage = UIImage.init(data: sticker.originalData!)
+        }else{
+            if mSticker!.locationPath.count == 0 {
+                BFLog(2, message: "图片数据为空,创建失败")
+                return
+            }
+            
+            var imageFilePath = mSticker?.locationPath ?? ""
+            if (!imageFilePath.contains("var/mobile/Media")) {
+                imageFilePath = documensDirectory + imageFilePath
+            }
+            BFLog(message: "imageFilePath is \(imageFilePath)")
+            newImage = UIImage(contentsOfFile:imageFilePath)
         }
-        newImage = UIImage(contentsOfFile: documensDirectory + sticker.locationPath)
+
         // try find image file frome in BFFramework bundle
         if newImage == nil {
             newImage = UIImage.moduleImage(named: sticker.locationPath, moduleName: "BFFramework", isAssets: false)
@@ -55,10 +68,15 @@ open class PQImageFilter: PQBaseFilter {
 
         autoreleasepool {
             if newImage == nil {
-                let filePath = documensDirectory + (mSticker?.locationPath ?? "")
-                if FileManager.default.fileExists(atPath: filePath) {
+                //有可能是webp数据 ,使用 webp 加载
+                var imageFilePath = mSticker?.locationPath ?? ""
+                if (!imageFilePath.contains("var/mobile/Media")) {
+                    imageFilePath = documensDirectory + imageFilePath
+                }
+                BFLog(message: "imageFilePath is \(imageFilePath)")
+                if FileManager.default.fileExists(atPath: imageFilePath) {
                     // 有可能是 WEBP
-                    let fileData: Data = try! Data(contentsOf: URL(fileURLWithPath: filePath))
+                    let fileData: Data = try! Data(contentsOf: URL(fileURLWithPath: imageFilePath))
                     if fileData.count != 0, fileData.isWebPFormat {
                         newImage = WebPProcessor.default.process(item: ImageProcessItem.data(fileData), options: KingfisherParsedOptionsInfo([.onlyLoadFirstFrame, .scaleFactor(1)]))
                     }