ios 裁剪图片(1裁多)
裁剪图片:(C类库方法)
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 60, 90)];
[self.view addSubview:iv];
//得到僵尸的完整图片
UIImage *zombImage = [UIImage imageNamed:@"zomb_2"];
// ************截取单张图片
// 截取里面的图片 CG开头
CGImageRef subImage = CGImageCreateWithImageInRect(zombImage.CGImage, CGRectMake(0, 0, zombImage.size.width/8, zombImage.size.height));
// 把CGImage转成 UIImage
iv.image = [UIImage imageWithCGImage:subImage];
//释放用完的CG图片
CGImageRelease(subImage);
// *******************截取每一张
NSMutableArray *images = [NSMutableArray array];
// 0w 1w 2w 3w
for (int i=0; i<8; i++) {
CGImageRef imageRef = CGImageCreateWithImageInRect(zombImage.CGImage, CGRectMake(i*(zombImage.size.width/8), 0, zombImage.size.width/8, zombImage.size.height));
[images addObject:[UIImage imageWithCGImage:imageRef]];
//把用完的imageRef释放(CG...框架没有自动释放池,需要手动释放)
CGImageRelease(imageRef);
}
//设置动画的代码
[iv setAnimationImages:images];
[iv setAnimationDuration:1];
[iv setAnimationRepeatCount:0];
[iv startAnimating];
}
成功的三大原则:
1、坚持
2、不要脸
3、坚持不要脸