UIImage *srcimg = [UIImage imageNamed:@"test.png"];////test.png宽172 高192
NSLog(@"image width = %f,height = %f",srcimg.size.width,srcimg.size.height);
UIImageView *imgview = [[UIImageView alloc] init];
imgview.frame = CGRectMake(10, 150, 300, 220);
CGRect rect = CGRectMake(0, 0, 300, 100);//要裁剪的图片区域,按照原图的像素大小来,超过原图大小的边自动适配
CGImageRef cgimg = CGImageCreateWithImageInRect([srcimg CGImage], rect);
imgview.image = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);//用完一定要释放,否则内存泄露
[self.view addSubview:imgview];
ios裁剪图片
最新推荐文章于 2024-05-11 16:33:06 发布