【发布时间】:2011-12-19 10:49:15
【问题描述】:
我有一些 UIViews 应用了不同的中心和变换。 我想将这些视图重建到位图上下文中。 (基本上我想将用户在屏幕上创建的内容渲染到电影文件中)
我能够使在上下文中呈现的视图看起来几乎正确,但似乎存在偏移。我在想问题是 UIImageView 的 .center 属性没有反映在我正在做的转换中。但是我不确定该怎么做。 请注意,UIView 最初是相对于 1024x768 ipad 屏幕定位/转换的,其中视频缓冲区为 352 x 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);
}
【问题讨论】:
标签: ios cocoa uikit core-graphics