但我的结果并不好(见结果).
请帮帮我这个问题,谢谢!
照片
视频
结果
UIVIEw到UIImage
UIGraphicsBeginImageContextWithOptions(vIEw.bounds.size,vIEw.opaque,0.0);[vIEw.layer renderInContext:UIGraphicsGetCurrentContext()];UIImage * img = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();
将UIImage添加到视频中
- (voID)showImage:(UIImage*)img toCompostion:(AVMutableVIDeoComposition *)composition fromTime:(CGfloat)fromTime toTime:(CGfloat)toTime vIDeoSize:(CGSize)size { CALayer *parentLayer = [CALayer layer]; CALayer *viLayer = [CALayer layer]; [parentLayer addSublayer:viLayer]; parentLayer.frame = CGRectMake(0,size.wIDth,size.height); viLayer.frame = CGRectMake(0,size.height); // 1 - set up the overlay CALayer *imgLayer = [CALayer layer]; [imgLayer setContents:(ID)[img CGImage]]; imgLayer.frame = CGRectMake(50,50,img.size.wIDth,img.size.height); // Oxy: bottom left [imgLayer setMasksToBounds:YES]; // 2 - set up the parent layer [parentLayer addSublayer:imgLayer]; // the code for the opacity animation which then removes the image imgLayer.opacity = 0.0; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; [animation setDuration:0.1]; //duration [animation setFromValue:[NSNumber numberWithfloat:0.0]]; [animation setTovalue:[NSNumber numberWithfloat:1.0]]; [animation setBeginTime:fromTime]; // time to show text [animation setRemovedOnCompletion:NO]; [animation setFillMode:kCAFillModeForwards]; [imgLayer addAnimation:animation forKey:@"animateOpacity"]; animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; [animation setDuration:0.1]; //duration [animation setFromValue:[NSNumber numberWithfloat:1.0]]; [animation setTovalue:[NSNumber numberWithfloat:0.0]]; [animation setBeginTime:toTime]; // time to show text [animation setRemovedOnCompletion:NO]; [animation setFillMode:kCAFillModeForwards]; [imgLayer addAnimation:animation forKey:@"animateOpacity1"]; //// // 3 - apply magic composition.animationTool = [AVVIDeoCompositionCoreAnimationTool vIDeoCompositionCoreAnimationToolWithPostProcessingAsVIDeolayer:viLayer inLayer:parentLayer];}
********更新1 ********
如果我这样做就可以了:
(1)将UIGraphicsBeginImageContextWithOptions的比例从0.0改为1.0.
(2)将图像保存到文件中.
(3)等待0.01秒并回读该文件.
我不知道为什么需要保存到文件????
>图像图层大小小于父图层的实际高度.
>图像的宽高比与图层的宽高比不匹配.
在您的代码中,检查“父层”帧大小和“图像层”帧
总结以上是内存溢出为你收集整理的ios – 将图像添加到视频但它被扭曲了全部内容,希望文章能够帮你解决ios – 将图像添加到视频但它被扭曲了所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)