我目前正在编辑 FTCoreText 模块以直接从网络加载图像并使用 Core Text 显示它们。
因此,我对https://github.com/FuerteInternational/FTCoreText/blob/master/FTCoreText/classes/FTCoreTextView.m#L1149进行了一些编辑,以使用 AFNetworking 的 UIImageView 类别。现在,我使用一个块从互联网下载图像并将其绘制到视图中。图像已绘制,但上下文有误:
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextSaveGState: invalid context 0x0
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextSaveGState: invalid context 0x0
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextSetBlendMode: invalid context 0x0
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextSetAlpha: invalid context 0x0
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextTranslateCTM: invalid context 0x0
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextScaleCTM: invalid context 0x0
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextDrawImage: invalid context 0x0
Aug 13 05:34:50 Yohann-iPhone CCFA[9878] <Error>: CGContextRestoreGState: invalid context 0x0
你可以在这里看到我的块:
UIImageView *imgNode = [[UIImageView alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imageNode.imageName]];
[imgNode setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"rien.gif"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
if (alignment == kCTRightTextAlignment) x = (self.frame.size.width - image.size.width);
if (alignment == kCTCenterTextAlignment) x = ((self.frame.size.width - image.size.width) / 2);
frame = CGRectMake(x, (lineFrame.origin.y - image.size.height), image.size.width, image.size.height);
if (alignment != kCTCenterTextAlignment) frame.origin.x = (alignment == kCTLeftTextAlignment)? insets.left : (self.frame.size.width - image.size.width - insets.right);
frame.origin.y += insets.top;
frame.size.width = ((insets.left + insets.right + image.size.width ) > self.frame.size.width)? self.frame.size.width : image.size.width;
frame = CGRectMake((((320-2*20)-image.size.width)/2), frame.origin.y, image.size.width, image.size.height);
NSLog(@"Frame : %f %f", frame.size.width, frame.size.height);
NSLog(@"Image : %f %f", image.size.width, image.size.height);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
[image drawInRect:CGRectIntegral(frame)];
} failure:nil];
[imgNode.image drawInRect:CGRectIntegral(frame)];
当然,我将整个代码粘贴到你这里:http: //pastebin.com/Qj6PtEFj
我希望你能帮帮我 :) !