user331914
user331914

Reputation:

UIGraphicsBeginImageContext question in Objective C

I need the UIGraphicsBeginImageContext(self.view.frame.size); changed to where the .frame part pulls from webView

- (void) save {
    UIGraphicsBeginImageContext(self.view.frame.size); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
    NSLog(@"TEST");
}

WEBVIEW CODE:

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)ntype {
    NSLog(@"Scheme: %@", request.URL.scheme);

    if ([request.URL.scheme isEqualToString:@"save"]) {
        [self save];
    }

    return true;
}

Upvotes: 0

Views: 1968

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 186984

It's a little unclear what you are asking. But I think you want to render a webview into this image.

So assuming the web view is assigned to an instance variable like webView, then you can simply replace self.view with webView.

- (void) save {
    UIGraphicsBeginImageContext(webView.frame.size); 
    [webView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
    NSLog(@"TEST");
}

Upvotes: 2

Related Questions