图片裁剪工具类

来源:互联网 发布:浏览器兼容性测试软件 编辑:程序博客网 时间:2024/05/16 08:52

(4S例子)

注意CG是C语言基础上的图像处理,其坐标系为640 960 UI是基于Retina 屏幕的坐标系 所以其坐标系为320 480

-(UIImage*)getSubImage:(CGRect)rect{    #pragma -mark  注意UI坐标系 是CG坐标系的2倍  所以要转化为CG坐标系需要X2    rect = CGRectMake(rect.origin.x*2, rect.origin.y*2, rect.size.width*2, rect.size.height*2);    CGImageRef subImageRef = CGImageCreateWithImageInRect(self.CGImage, rect);    CGRect smallBounds = CGRectMake(0, 0, CGImageGetWidth(subImageRef), CGImageGetHeight(subImageRef));        UIGraphicsBeginImageContext(smallBounds.size);    CGContextRef context = UIGraphicsGetCurrentContext();    CGContextDrawImage(context, smallBounds, subImageRef);    UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];    UIGraphicsEndImageContext();        return smallImage;}


0 0
原创粉丝点击