//view
- (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;
}
//可以改变图片的尺寸
-(UIImage *)scaleToSize:(UIImage *)image size:(CGSize)size
{
//创建一个bitmap的context
//并把他设置成当前的context
UIGraphicsBeginImageContext(size);
//绘制图片的大小
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
//从当前context中创建一个改变大小后的图片
UIImage *endImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return endImage;
}
- (void)zip{
UIImage *image = [UIImage imageNamed:@""];
//压缩的比例,范围是 0.1~1
NSData *data=UIImageJPEGRepresentation(image, 0.1);
}