首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

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

2012-06-26 
iphone开发秘籍里面的捕捉屏幕截图代码+ (UIImage *) imageFromView: (UIView *) theView{//Draw a view`s

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]; 
}

热点排行