|
@@ -29,7 +29,7 @@ class OJAImageFrameInput: NSObject {
|
|
|
super.init()
|
|
|
}
|
|
|
|
|
|
- init(templateItem: OJATemplateItemModel) {
|
|
|
+ init(templateItem: OJATemplateItemModel, fatherItem: OJATemplateItemModel? = nil) {
|
|
|
self.templateItem = templateItem
|
|
|
var image = kWSSTemplateAddVideoPlaceholderImage
|
|
|
|
|
@@ -60,6 +60,42 @@ class OJAImageFrameInput: NSObject {
|
|
|
// if let temp = resultImage.oja_imageByResize(to: CGSize(width: 540, height: 960), contentMode: .scaleAspectFill) {
|
|
|
// resultImage = temp
|
|
|
// }
|
|
|
+
|
|
|
+ // 图片裁剪处理 fix: 补充创意模板 如 老虎机 使用 templateItemModel 里面的 comps 参数,还需要用到 x y 的中心点 父类的宽高进行 处理裁剪素材
|
|
|
+ if let superItem = fatherItem {
|
|
|
+ let boundsSize = CGSize(width: superItem.w, height: superItem.h)
|
|
|
+ let identifyRect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
|
|
|
+
|
|
|
+ let centerPoint = CGPoint(x: templateItem.x, y: templateItem.y)
|
|
|
+ let offsetX = -(centerPoint.x - templateItem.w * 0.5)
|
|
|
+ let offsetY = (centerPoint.y - templateItem.h * 0.5)
|
|
|
+
|
|
|
+ let cropRect = CGRect(x: offsetX / templateItem.w,
|
|
|
+ y: offsetY / templateItem.h,
|
|
|
+ width: boundsSize.width / templateItem.w,
|
|
|
+ height: boundsSize.height / templateItem.h)
|
|
|
+
|
|
|
+ WSSSimpleLog("=========>croprect:\(cropRect)")
|
|
|
+ if identifyRect != cropRect {
|
|
|
+ let semaphore = DispatchSemaphore(value: 0)
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let imageSizeW = image.size.width
|
|
|
+ let imageSizeH = image.size.height
|
|
|
+ let realRect = CGRect(x: cropRect.origin.x * imageSizeW,
|
|
|
+ y: cropRect.origin.y * imageSizeH,
|
|
|
+ width: cropRect.size.width * imageSizeW,
|
|
|
+ height: cropRect.size.height * imageSizeH)
|
|
|
+ if let cropImage = image.oja_imageByCrop(to: realRect) {
|
|
|
+ image = cropImage
|
|
|
+ semaphore.signal()
|
|
|
+ } else {
|
|
|
+ semaphore.signal()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ semaphore.wait()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
pictureFile = OJAImagePicture(image: image)
|
|
|
pictureFile.processImageFrame(at: CMTime.zero)
|
|
|
super.init()
|