ios中图片的绘画和截图
ios中图片的绘画和截图
CGImageCreateWithImageInRect截图和UIGraphicsGetImageFromCurrentImageContext绘画图片
使用CGImageCreateWithImageInRect截图
UIImage *img1 = [UIImage imageNamed:@"123"];
//截取图片
CGImageRef imgSmall = CGImageCreateWithImageInRect(img1.CGImage, CGRectMake(100, 100, 100, 100));
UIImage *img2 = [UIImage imageWithCGImage:imgSmall];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img2];
[imgView setFrame:CGRectMake(0, 100, 100, 100)];
[self.view addSubview:imgView];
使用UIGraphicsGetImageFromCurrentImageContext绘画图片
UIImage *img1 = [UIImage imageNamed:@"123"];
UIImage *img2 = [UIImage imageNamed:@"123"];
//开始绘画,设置画布的大小
UIGraphicsBeginImageContext(CGSizeMake(img1.size.width, img1.size.height * 2));
//将图片画进去
[img1 drawInRect:CGRectMake(0, 0, img1.size.width, img1.size.height)];
[img2 drawInRect:CGRectMake(0,img1.size.height, img1.size.width, img1.size.height)];
//就画布中的内容,放置到图片中
UIImage *img3 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//在视图中显示
UIImageView *imgView = [[UIImageView alloc] initWithImage:img3];
[imgView setFrame:CGRectMake(0, 100, 100, 100)];
[self.view addSubview:imgView];