【发布时间】:2014-05-09 19:15:46
【问题描述】:
我想是什么让我的问题/问题与其他帖子不同的是,我不是在缩放视图,而是资产层指令 (AVMutableVideoCompositionLayerInstruction)。所以设置锚点、view.center、CG Rect 缩放都不起作用。
除了使用 CGAffineTransformMakeTranslation 移动资产以使其看起来像居中但高度不准确之外,我无法弄清楚如何使其从中心缩放。有没有我失踪的财产?文档和指南不是很有帮助,但也许我错过了一些东西。
代码如下。谢谢大家!!! :)
另外,对于那些正在寻找使用 CGTransforms 导出 avasset 的方法的人,下面的代码是到达那里的所有步骤;当然需要填写诸如 CMTimeRanges 之类的详细信息,但希望这可以帮助某人弄清楚这个令人困惑的事情。
-(void) goAssetsExport {
AVMutableComposition *composition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *firstTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.frameDuration = CMTimeMake(1,30);
videoComposition.renderScale = 1.0;
videoComposition.renderSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height);
NSURL *movieURL = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"%@", [preloadEffectsArray objectAtIndex:i]] withExtension:@"mov"];
AVURLAsset *firstAsset = [AVURLAsset URLAssetWithURL:movieURL options:nil];
AVAssetTrack *firstAssetTrack = [[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[firstTrack insertTimeRange:CMTimeRangeMake(firstTrackRangeMin, duration) ofTrack:firstAssetTrack atTime:firstTrackRangeMin error:nil];
AVMutableVideoCompositionInstruction *transitionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
AVMutableVideoCompositionLayerInstruction *fromLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:firstTrack];
//**This is where problem might be?**//
CGAffineTransform Scaler = CGAffineTransformMakeScale(scaleNumber,scaleNumber);
CGAffineTransform Mover = CGAffineTransformMakeTranslation(scaleNumber * -100, scaleNumber * -150);
[fromLayer setTransform:CGAffineTransformConcat(Scaler,Mover) atTime:firstTrackRangeMin];
transitionInstruction.layerInstructions = [NSArray arrayWithObject:fromLayer];
videoComposition.instructions = instructionArray;
[self exportVideo:composition withInstructionComposition:videoComposition];
}
【问题讨论】:
-
“从中心缩放”不是很清楚你的意思是什么 与旋转不同,缩放是位置不敏感的。
-
嗨大卫,如果不清楚,对不起。我希望图像在屏幕中间以更大的比例缩放。现在它缩放得更大,但从屏幕左上角开始缩放更大。
-
现在看起来您的变换将向上和向左移动图像。你想要的是通过delta width / 2,delta height / 2(缩放后)进行翻译
-
抱歉回复晚了,但我正在尝试不同的方法来使增量或更改正常工作。它接近的唯一方法是向移动器添加偏移量(int offset = scaleNumber * 100)。 (CGAffineTransform Mover = CGAffineTransformMakeTranslation(deltaWidth/2 + offset, deltaHeight/2 + offset); 我希望有一个属性可以让资产以视图为中心。继续尝试不同的方法,欢迎任何其他建议。谢谢大卫。
标签: ios cgaffinetransform avmutablecomposition avasset cgaffinetransformscale