下面是一个方法,用的时候只用调用这个方法并给他传一张你要的合成的图片就好
//截图
-(UIImage*)convertViewToImage{
CGSize muhuSize = CGSizeMake(HXWidth,HXWidth);
UIGraphicsBeginImageContextWithOptions(muhuSize, NO, [UIScreen mainScreen].scale);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGRect rect = CGRectMake(0, 0, theImage.size.width*3, theImage.size.height*3);
CGImageRef imageRef = theImage.CGImage;
CGImageRef imagePartRef = CGImageCreateWithImageInRect(imageRef, rect);
UIImage *cropImage = [UIImage imageWithCGImage:imagePartRef];
CGImageRelease(imagePartRef);
return cropImage;
}
调用的代码
UIImage *image = [self convertViewToImage];
publish.croppedImage = image;