1

I'm working on something that will create an email and attach an image of the screen for the user to send. I'm using the following code to create and attach the image.

    UIGraphicsBeginImageContext([self.view frame].size);
    [[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIGraphicsBeginImageContext([self.view bounds].size);
    [myImage drawInRect:CGRectMake(0, 0, [self.view bounds].size.width,[self.view bounds].size.height)];
    myImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *imageData = UIImagePNGRepresentation(myImage);
    [mailer addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"blah"];

However, this includes all of the subviews, and I want to exclude a toolbar and a segmented view, leaving only the view above the toolbar and the text field in that view. I've tagged all the relevant views and subviews, but how do I use those tags to create an image that includes what I want and excludes what I don't want?

4

1 回答 1

3

在渲染图像之前,将所有不想显示的视图设置为隐藏。我有几个应用程序可以做同样的事情,这就是我所做的。

renderInContext和相关功能基本都是截图,所以所见即所得

于 2012-08-09T12:09:03.003 回答