2010-07-01 69 views
1

我想創建一個UIWebView的UIImage,然後我想繪製該圖像。創建UIView圖像的問題

這裏是我的代碼:

UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)]; 
tempView.backgroundColor = [UIColor blueColor]; 

UIGraphicsBeginImageContext(tempView.bounds.size); 
    [tempView drawRect:tempView.bounds]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height); 
CGContextDrawImage(ctx, imageRect, [image CGImage]); 

,但它不是畫比一個空白頁面的任何其他。不能我們創建這樣的UIImage,或者我在代碼中的某處做了什麼錯誤。

感謝名單

回答

4

下面的代碼應該工作:

UIGraphicsBeginImageContext(tempView.bounds.size); 
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
+0

感謝名單現在是工作 – Ideveloper 2010-07-01 12:06:25