图片的处理

1图片处理只拿到图片的一部分

UIImage *image = [UIImage imageNamed:filename];

CGImageRef imageRef = image.CGImage;

CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height);

//这里的宽高是相对于图片的真实大小

//比如你的图片是400x400的那么(0,0,400,400)就是图片的全尺寸,想取哪一部分就设置相应坐标即可

CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);

UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect];

2给UIView设置图片

UIImage *image = [UIImage imageNamed:@"playing"];

_layerView.layer.contents = (__bridge id)image.CGImage;

_layerView.layer.contentsCenter = CGRectMake(0.25, 0.25, 0.5, 0.5);

//同样可以设置显示的图片范围

//不过此处略有不同,这里的四个值均为0-1之间;对应的依然是写x,y,widt,height

posted @ 2016-08-10 14:45  qinxiaoguang  阅读(101)  评论(0编辑  收藏  举报