0
我有一些UIView,它们应用了不同的中心和变换。 我想重建这些视图上的位图上下文。 (基本上我想要拍摄用户在屏幕上创建的内容并将其渲染到电影文件中)以与UIView呈现类似的方式绘制使用renderInContext
我能够在上下文中看到呈现的视图差不多正确但是似乎存在偏移。我在想这个问题是UIImageView的.center属性没有反映在我正在做的转换中。但我不确定如何去做。 注意,UIViews最初被定位/相对于1024×768屏幕的ipad其中作为视频缓冲器是352×288像素
转化如果我只需添加一个CGContextTranslateCTM(newContext,img.center.x,img.center.y )然后一切看起来完全关闭。任何想法如何正确地将视图转换到正确的中心?
CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGContextRotateCTM(newContext, M_PI_2);
CGContextScaleCTM(newContext, 1, -1);
for(int i=0; i<[self.renderObjects count]; i++){
UIImageView * img = [self.renderObjects objectAtIndex:i];
[img setNeedsDisplay];
[img setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.2]];
CGContextSaveGState(newContext);
CGContextScaleCTM(newContext, 0.375, 0.34);
CGContextConcatCTM(newContext, img.transform);
[img.layer renderInContext:newContext];
CGContextRestoreGState(newContext);
}