[英]How to render UIView into a CGContext
我想將UIView渲染成CGContextRef
-(void)methodName:(CGContextRef)ctx {
UIView *someView = [[UIView alloc] init];
MagicalFunction(ctx, someView);
}
因此,這里的MagicalFunction應該將UIView(可能是它的圖層)渲染到當前上下文中。
我怎么做?
提前致謝!
CALayer的renderInContext方法怎么樣?
-(void)methodName:(CGContextRef)ctx {
UIView *someView = [[UIView alloc] init];
[someView.layer renderInContext:ctx];
}
編輯:如評論中所述,由於過程中涉及的兩個坐標系的起源不同,該圖層將呈現倒置。 要進行補償,您只需垂直翻轉上下文。 這在技術上通過縮放和平移變換完成,可以在單個矩陣變換中組合:
-(void)methodName:(CGContextRef)ctx {
UIView *someView = [[UIView alloc] init];
CGAffineTransform verticalFlip = CGAffineTransformMake(1, 0, 0, -1, 0, someView.frame.size.height);
CGContextConcatCTM(ctx, verticalFlip);
[someView.layer renderInContext:ctx];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.