我尝试改编他上周在这里给我的 Travis 的示例(C4 保存图像的一部分)以将屏幕保存为 C4Image。我认为它应该像这样工作:
CGFloat scale = 5.0;
//begin an image context
CGSize rect=CGSizeMake(self.canvas.width, self.canvas.height);
UIGraphicsBeginImageContextWithOptions(rect, NO, scale);
//create a new context ref
CGContextRef c = UIGraphicsGetCurrentContext();
//render the original image into the context
[self.canvas renderInContext:c];
//grab a UIImage from the context
UIImage *newUIImage = UIGraphicsGetImageFromCurrentImageContext();
//end the image context
UIGraphicsEndImageContext();
//create a new C4Image
self.currentAlphabetImage = [C4Image imageWithUIImage:newUIImage];
C4Log(@"self.currentAlphabetImage:%@", self.currentAlphabetImage);
self.currentAlphabetImage.width=self.canvas.width/2;
self.currentAlphabetImage.center=self.canvas.center;
self.currentAlphabetImage.backgroundColor=navBarColor;
[self.canvas addImage:self.currentAlphabetImage];
...即使日志给了我
self.currentAlphabetImage:C4Image: 0x15840970; baseClass = UIControl;
frame = (0 0; 320 568); layer = C4Layer: 0x15842590>>
...屏幕上什么都没有显示...但是,是的,画布上有些东西应该被捕获...
再说一次,我不知道怎么了。使用objectiveC的其他尝试也没有成功(例如,iOS Screenshot part of the screen)