我想用Uilabeltextfields保存图像。 我可以保存它们,但所有的文本字段都是黑色的。 我尝试从属性检查器更改但没有任何更改。 任何人都可以帮我保存白色的Uilabel文本字段。 我还需要粗体字符。
谢谢。
UIGraphicsBeginImageContextWithOptions(self.mainImage.bounds.size, YES, 0.0);
[self.mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.goalkeeperImage.image drawInRect:CGRectMake(self.goalkeeperImage.frame.origin.x, self.goalkeeperImage.frame.origin.y, self.goalkeeperImage.frame.size.width, self.goalkeeperImage.frame.size.height)];
[self.goalkeeperText.text drawInRect:CGRectMake(self.goalkeeperText.frame.origin.x, self.goalkeeperText.frame.origin.y, self.goalkeeperText.frame.size.width,self.goalkeeperText.frame.size.height) withAttributes:nil ];
[self.datelabeltext.text drawInRect:CGRectMake(self.datelabeltext.frame.origin.x, self.datelabeltext.frame.origin.y, self.datelabeltext.frame.size.width,self.datelabeltext.frame.size.height) withAttributes: nil ];
UIImage *SaveImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(SaveImage, self,@selector(image:didFinishSavingWithError:contextInfo:), nil);
答案 0 :(得分:0)
如果您尝试渲染的所有图像和标签都包含在一个视图中(并且不存在其他对象),则可以使用此代码捕获包含的视图:
// Draw the high resolution image to the context
UIGraphicsBeginImageContextWithOptions(drawView.bounds.size, NO, 0.0);
[[drawView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *ViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save the high resolution image as a png
NSData *pngData = UIImagePNGRepresentation(ViewImage);
[pngData writeToFile:@"__Path__/image@2x.png" atomically:NO];
// Draw the low resolution image to the context
UIGraphicsBeginImageContext(drawView.bounds.size);
[[drawView layer] renderInContext:UIGraphicsGetCurrentContext()];
ViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save the low resolution image as a png
pngData = UIImagePNGRepresentation(ViewImage);
[pngData writeToFile:@"__Path__/image.png" atomically:NO];
您可能不需要代码将图像保存为png,您可以使用ViewImage
作为您传递给另一个函数的UIImage。这只是我用来将视图保存为png的代码。