1、获得屏幕图像

- (UIImage *)imageFromView: (UIView *) theView

{

    

    UIGraphicsBeginImageContext(theView.frame.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    [theView.layer renderInContext:context];

    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return theImage;

}

//获得某个范围内的屏幕图像

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

}

2、将图像保存到图库中

   UIImageWriteToSavedPhotosAlbum([imageView image], nilnil,nil);

       UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"存储照片成功"

                                                 message:@"您已将照片存储于图片库中,打开照片程序即可查看。"

                                                 delegate:self

                                         cancelButtonTitle:@"OK"

                                         otherButtonTitles:nil];

       [alert show];

       [alert release];

posted on 2013-11-22 11:10  瓜甜甜  阅读(205)  评论(0编辑  收藏  举报