当前位置: 代码迷 >> Iphone >> iphone开发秘籍里边的捕捉屏幕截图代码
  详细解决方案

iphone开发秘籍里边的捕捉屏幕截图代码

热度:64   发布时间:2016-04-25 06:39:56.0
iphone开发秘籍里面的捕捉屏幕截图代码
+ (UIImage *) imageFromView: (UIView *) theView

{

    //Draw a view`s contents into an image context

    UIGraphicsBeginImageContext(theView.frame.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    [theView.layer renderInContext:context];

    UIGraphicsEndImageContext();

    return theImage;

}

--此函数要用到QuartzCore.framework框架


//获得某个范围内的屏幕图像 
- (UIImage *)imageFromView: (UIView *) theView   atFrame:(CGRect)r 

    UIGraphicsBeginImageContext(theView.frame.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSaveGState(context); 
    UIRectClip(r); 
    [theView.layer renderInContext:context]; 
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
     
    return  theImage;//[self getImageAreaFromImage:theImage atFrame:r]; 
}
  相关解决方案