UIView -> UIImage

iOS/참고 2013.02.19 11:13



QuartzCore.framework <- 추가해주세요.

#import <Quartzcore/Quartzcore.h>

- (UIImage*)CaptureToScreen:(UIView*)ScreenView
{
     CGRect screenRect = ScreenView.frame;
     UIGraphicsBeginImageContext(screenRect.size);
 
     CGContextRef ctx = UIGraphicsGetCurrentContext();
     [[UIColor blackColor] set];
     CGContextFillRect(ctx, screenRect);
 
     [ScreenView.layer renderInContext:ctx];
 
     UIImage* pimg = UIGraphicsGetImageFromCurrentImageContext();
 
     UIGraphicsEndImageContext();
    
    return pimg;
}

저작자 표시 비영리 변경 금지
신고
Posted by 까칠코더.


티스토리 툴바