实现:
1.实现空间照片转出hsbs格式并保存至相册
This commit is contained in:
parent
c097a26995
commit
e60458db5f
@ -10,6 +10,7 @@
|
|||||||
00B946212B67AC9D00DA668F /* CCSpatialPlayController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B946202B67AC9C00DA668F /* CCSpatialPlayController.swift */; };
|
00B946212B67AC9D00DA668F /* CCSpatialPlayController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B946202B67AC9C00DA668F /* CCSpatialPlayController.swift */; };
|
||||||
00B946232B67B26D00DA668F /* ddd_video.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 00B946222B67B26D00DA668F /* ddd_video.mp4 */; };
|
00B946232B67B26D00DA668F /* ddd_video.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 00B946222B67B26D00DA668F /* ddd_video.mp4 */; };
|
||||||
00B946252B67B7DE00DA668F /* CCSpatialPlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B946242B67B7DE00DA668F /* CCSpatialPlayView.swift */; };
|
00B946252B67B7DE00DA668F /* CCSpatialPlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B946242B67B7DE00DA668F /* CCSpatialPlayView.swift */; };
|
||||||
|
00D33BF42B998BF700604A44 /* SpatialImageConvertor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00D33BF32B998BF700604A44 /* SpatialImageConvertor.swift */; };
|
||||||
04E1D3F12B68EDFE00743F2F /* CCWebController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E1D3F02B68EDFE00743F2F /* CCWebController.swift */; };
|
04E1D3F12B68EDFE00743F2F /* CCWebController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E1D3F02B68EDFE00743F2F /* CCWebController.swift */; };
|
||||||
1E02C9322B8990C600DD3143 /* CCDeviceOperationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C9312B8990C600DD3143 /* CCDeviceOperationListView.swift */; };
|
1E02C9322B8990C600DD3143 /* CCDeviceOperationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C9312B8990C600DD3143 /* CCDeviceOperationListView.swift */; };
|
||||||
1E02C9342B89916C00DD3143 /* CCDeviceOperationListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C9332B89916C00DD3143 /* CCDeviceOperationListCell.swift */; };
|
1E02C9342B89916C00DD3143 /* CCDeviceOperationListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C9332B89916C00DD3143 /* CCDeviceOperationListCell.swift */; };
|
||||||
@ -91,6 +92,7 @@
|
|||||||
00B946202B67AC9C00DA668F /* CCSpatialPlayController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCSpatialPlayController.swift; sourceTree = "<group>"; };
|
00B946202B67AC9C00DA668F /* CCSpatialPlayController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCSpatialPlayController.swift; sourceTree = "<group>"; };
|
||||||
00B946222B67B26D00DA668F /* ddd_video.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = ddd_video.mp4; sourceTree = "<group>"; };
|
00B946222B67B26D00DA668F /* ddd_video.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = ddd_video.mp4; sourceTree = "<group>"; };
|
||||||
00B946242B67B7DE00DA668F /* CCSpatialPlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCSpatialPlayView.swift; sourceTree = "<group>"; };
|
00B946242B67B7DE00DA668F /* CCSpatialPlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCSpatialPlayView.swift; sourceTree = "<group>"; };
|
||||||
|
00D33BF32B998BF700604A44 /* SpatialImageConvertor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpatialImageConvertor.swift; sourceTree = "<group>"; };
|
||||||
04E1D3F02B68EDFE00743F2F /* CCWebController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCWebController.swift; sourceTree = "<group>"; };
|
04E1D3F02B68EDFE00743F2F /* CCWebController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCWebController.swift; sourceTree = "<group>"; };
|
||||||
1E02C9312B8990C600DD3143 /* CCDeviceOperationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCDeviceOperationListView.swift; sourceTree = "<group>"; };
|
1E02C9312B8990C600DD3143 /* CCDeviceOperationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCDeviceOperationListView.swift; sourceTree = "<group>"; };
|
||||||
1E02C9332B89916C00DD3143 /* CCDeviceOperationListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCDeviceOperationListCell.swift; sourceTree = "<group>"; };
|
1E02C9332B89916C00DD3143 /* CCDeviceOperationListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCDeviceOperationListCell.swift; sourceTree = "<group>"; };
|
||||||
@ -220,6 +222,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
1E1EA2952B936C9600A5D5D2 /* VideoConvertor2.swift */,
|
1E1EA2952B936C9600A5D5D2 /* VideoConvertor2.swift */,
|
||||||
|
00D33BF32B998BF700604A44 /* SpatialImageConvertor.swift */,
|
||||||
1E1EA28F2B933C8200A5D5D2 /* VideoWriter.swift */,
|
1E1EA28F2B933C8200A5D5D2 /* VideoWriter.swift */,
|
||||||
1EE5C5F92B8F97BF00EDFC2F /* SpatialVideoWriter.swift */,
|
1EE5C5F92B8F97BF00EDFC2F /* SpatialVideoWriter.swift */,
|
||||||
);
|
);
|
||||||
@ -611,6 +614,7 @@
|
|||||||
1EFAF0C02B8B7A59002A1773 /* VRPhotoTransformController.swift in Sources */,
|
1EFAF0C02B8B7A59002A1773 /* VRPhotoTransformController.swift in Sources */,
|
||||||
AF21210B2B4EA7FE00400B7F /* CCRequest.swift in Sources */,
|
AF21210B2B4EA7FE00400B7F /* CCRequest.swift in Sources */,
|
||||||
AF2120D82B4E9AC500400B7F /* CCAddImageView.swift in Sources */,
|
AF2120D82B4E9AC500400B7F /* CCAddImageView.swift in Sources */,
|
||||||
|
00D33BF42B998BF700604A44 /* SpatialImageConvertor.swift in Sources */,
|
||||||
AF2120B32B4E94BE00400B7F /* CCDefine.swift in Sources */,
|
AF2120B32B4E94BE00400B7F /* CCDefine.swift in Sources */,
|
||||||
1EEF683E2B8D079600B953F7 /* CCVRPreviewController.swift in Sources */,
|
1EEF683E2B8D079600B953F7 /* CCVRPreviewController.swift in Sources */,
|
||||||
04E1D3F12B68EDFE00743F2F /* CCWebController.swift in Sources */,
|
04E1D3F12B68EDFE00743F2F /* CCWebController.swift in Sources */,
|
||||||
|
|||||||
@ -225,13 +225,33 @@ class VRPhotoTransformController: BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//空间图片才能进行3D格式的转换,普通图片没有这些参数
|
//空间图片才能进行3D格式的转换,普通图片没有这些参数
|
||||||
|
switch mTabView?.datas.first?.type {
|
||||||
|
case .hsbs_3D:
|
||||||
|
let result:UIImage = SpatialImageConvertor.convertToHSBS(imageData: sourceImageData!)!
|
||||||
|
UIImageWriteToSavedPhotosAlbum(result, self, #selector(completeSaveImg(_:error:contextInfo:)), nil)
|
||||||
|
case .fsbs_3D:
|
||||||
|
let result:UIImage = SpatialImageConvertor.convertToHSBS(imageData: sourceImageData!)!
|
||||||
|
UIImageWriteToSavedPhotosAlbum(result, self, #selector(completeSaveImg(_:error:contextInfo:)), nil)
|
||||||
|
|
||||||
|
default:
|
||||||
|
print("不执行...")
|
||||||
|
}
|
||||||
|
|
||||||
}else if(sender.tag == 11){
|
}else if(sender.tag == 11){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@objc func completeSaveImg(_ image: UIImage, error: NSError?, contextInfo: UnsafeRawPointer?) {
|
||||||
|
if let error = error {
|
||||||
|
print("保存失败:\(error)")
|
||||||
|
SVProgressHUD.showError(withStatus: "导入手机相册失败,请查看相册权限")
|
||||||
|
} else {
|
||||||
|
SVProgressHUD.showSuccess(withStatus: "转码成功,已导入手机相册")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//MARK: - action
|
//MARK: - action
|
||||||
func selectedCellAction(_ model:(type:CCTransformParameterType,title:String,name:String)) {
|
func selectedCellAction(_ model:(type:CCTransformParameterType,title:String,name:String)) {
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
//
|
||||||
|
// SpatialImageConvertor.swift
|
||||||
|
// SwiftProject
|
||||||
|
//
|
||||||
|
// Created by aaa on 2024/3/7.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import UIKit
|
||||||
|
class SpatialImageConvertor {
|
||||||
|
//将空间照片转换为hsbs格式
|
||||||
|
public class func convertToHSBS(imageData:Data) -> UIImage? {
|
||||||
|
let (left_uiimage,right_uiimage) = SpatialImageConvertor.getLeftAndRightImgFrom(imageData: imageData)
|
||||||
|
let newpb = SpatialImageConvertor.joinImages_sbs( left: left_uiimage!, right:right_uiimage! ,imgWidth: left_uiimage!.size.width,imgHeight:left_uiimage!.size.height)
|
||||||
|
let lastImg = SpatialImageConvertor.convertCIImageToUIImage(ciImage: newpb)!
|
||||||
|
return lastImg
|
||||||
|
}
|
||||||
|
|
||||||
|
class func getLeftAndRightImgFrom(imageData:Data) -> (left_uiimage:UIImage?,right_uiimage:UIImage?){
|
||||||
|
guard let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil) else {
|
||||||
|
return (nil,nil)
|
||||||
|
}
|
||||||
|
let frameCount = CGImageSourceGetCount(imageSource)
|
||||||
|
var frames: [CGImage] = []
|
||||||
|
for index in 0..<frameCount {
|
||||||
|
guard let frameImage = CGImageSourceCreateImageAtIndex(imageSource, index, nil) else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
frames.append(frameImage)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(frames.count < 2){return (nil,nil) }
|
||||||
|
let lciImage = CIImage(cgImage: frames.first!)
|
||||||
|
let rciImage = CIImage(cgImage: frames[1])
|
||||||
|
|
||||||
|
let left_uiimage = UIImage(ciImage: lciImage )
|
||||||
|
let right_uiimage = UIImage(ciImage: rciImage )
|
||||||
|
return (left_uiimage,right_uiimage)
|
||||||
|
}
|
||||||
|
|
||||||
|
class func convertCIImageToUIImage(ciImage: CIImage) -> UIImage? {
|
||||||
|
let context = CIContext(options: nil)
|
||||||
|
if let cgImage = context.createCGImage(ciImage, from: ciImage.extent) {
|
||||||
|
let uiImage = UIImage(cgImage: cgImage)
|
||||||
|
return uiImage
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//将两张图片合成一张图片
|
||||||
|
class func joinImages_sbs( left:UIImage, right:UIImage,imgWidth:CGFloat,imgHeight:CGFloat) -> CIImage {
|
||||||
|
let newImageSize = CGSize(width:imgWidth, height: imgHeight);
|
||||||
|
UIGraphicsBeginImageContextWithOptions(newImageSize, false, 1);
|
||||||
|
left.draw(in: CGRect(x:0, y:0, width:imgWidth/2, height:imgHeight))
|
||||||
|
right.draw(in: CGRect(x:imgWidth/2, y:0, width:imgWidth/2, height:imgHeight))
|
||||||
|
let image = UIGraphicsGetImageFromCurrentImageContext()!
|
||||||
|
UIGraphicsEndImageContext();
|
||||||
|
|
||||||
|
let ci = CIImage(cgImage: image.cgImage!)
|
||||||
|
return ci
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user