0
美好的一天;CATiledLayer或CALayer繪圖UIImage不能正常工作
我想手動(不使用子圖層)在CATiledLayer內繪製圖像,但它不像應用定義的解決方案那樣運行。我承諾,當你調用'CGContextDrawImage'時,你必須縮放和翻譯以便翻轉它,但是我不能爲了我的生活,讓它工作。
我有一個名爲
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image
方法,在
- (void)drawInContext:(CGContextRef)context
打過幾次電話從渲染所有進入CATileLayer圖像。
下使無圖像:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, image.CGImage);
CGContextRestoreGState(context);
下產生圖像,但呈現不正確:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextDrawImage(context, rect, image.CGImage);
像明智的這樣:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, image.CGImage);
我也有嘗試:
UIGraphicsBeginImageContext
UIGraphicsEndImageContext
和
UIGraphicsPushContext
UIGraphicsPopContext
所有不起作用。我錯過了一些基本的東西,我懷疑我的方法來保存上下文不起作用。