views:

286

answers:

1

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;
}
+1  A: 

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");
}
Squeegy
Thats correct, but it says Undeclared.
Henry D'Andrea
Wait no, I didnt; I need help declaring it in the .h file
Henry D'Andrea
in the .h: `IBOutlet UIWebView *webView;` then link that to the the `webView` outlet in interface builder, or create it in code. Then `webView` will be an instance variable representing your `UIWebView`. If all this is confusing, you may want to take a few steps back and learn more fundamentals before tackling anything too complex.
Squeegy
Thank you it worked!
Henry D'Andrea
Is there a way for it to be not in IBOutlet. Its all code. No IB
Henry D'Andrea
`webView = [[UIWebView alloc] initWithFrame:someFrame]`. Just be sure to pair it with a `[webView release]` in your controller's `dealloc` method.
Squeegy
IBOutlet is just used as a hint it IB. It has no real impact on the code. See the define for it.
chrish