在接收数据的套接字流中,我可以将NSMutableData
放入图片并能够保存在照片中但无法将NSMutableData
转换为视频
我正在做的图像
UIImage *imagess = [[UIImage alloc]initWithData:received];
//dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImageWriteToSavedPhotosAlbum(imagess, nil, nil, nil);
});
有人帮我做同样的视频吗?
答案 0 :(得分:0)
首先,您需要将视频另存为本地文件。
NSData *receivedData;
…
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"movie.mp4"];
[receivedData writeToFile:path atomically:YES];
然后你可以使用UISaveVideoAtPathToSavedPhotosAlbum函数将视频文件保存到Photo roll。
NSURL movieURL=[NSURL fileURLWithPath:path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(movieURL)){
UISaveVideoAtPathToSavedPhotosAlbum(movieURL, nil, nil, nil);
}