// // UIView+YHExtend.m // YouHuiProject // // Created by jcymac on 2018/5/19. // Copyright © 2018年 kuxuan. All rights reserved. // #import "UIView+YHExtend.h" @implementation UIView (YHExtend) -(UIImage *)changeToImage{ // UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0); //NO,YES 控制是否透明 // // [self.layer renderInContext:UIGraphicsGetCurrentContext()]; // // UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); // // CGRect myImageRect = self.bounds; // // CGImageRef imageRef = image.CGImage; // // CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef,myImageRect ); // // // // CGContextRef context = UIGraphicsGetCurrentContext(); // // CGContextDrawImage(context, myImageRect, subImageRef); // // UIImage* smallImage = [UIImage imageWithCGImage:subImageRef]; // // CGImageRelease(subImageRef); // // UIGraphicsEndImageContext(); // return smallImage; CGSize s = self.bounds.size; // 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了 UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage*image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } @end