首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CGAffineTransform比例尺不从中心缩放-有出口

CGAffineTransform比例尺不从中心缩放-有出口
EN

Stack Overflow用户
提问于 2014-05-09 19:15:46
回答 1查看 3.2K关注 0票数 3

我想我的问题/问题与其他帖子不同之处在于,我不是在缩放视图,而是一个资产层指令(AVMutableVideoCompositionLayerInstruction)。所以设置锚点,view.center,CG重新缩放都不起作用。

除了用CGAffineTransformMakeTranslation移动资产以使其看起来像以中心为中心,但这是非常不准确的,我不知道如何使它的规模从中心。我有失窃的财产吗?医生和导游不是很有用,但也许我漏掉了什么。

密码在下面。谢谢各位:)

另外,对于那些寻找用CGTransforms导出avasset的方法的人来说,下面的代码是实现这个目标的所有步骤;当然,需要像CMTimeRanges这样的细节,但是希望这能帮助人们解决这个困惑的问题。

代码语言:javascript
复制
-(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];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-15 16:24:44

CGAffineTransform在Quartz坐标系中工作,这是您应该从这里开始的点:

代码语言:javascript
复制
CGAffineTransform  translate = CGAffineTransformMakeTranslation((x,y);
CGAffineTransform  scale = CGAffineTransformMakeScale(q,z);
CGAffineTransform finalTransform = CGAffineTransformConcat(scale, CGAffineTransformConcat(translate, assetTrackForVideo1.preferredTransform));
        [layerInstructionForVideo setTransform:finalTransform atTime:kCMTimeZero];
        [layerInstructions addObject:layerInstructionForVideo];

这种转变对我来说是可行的。

编辑:我的错误,忘记编辑所有的代码!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23572295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档