-(UIImage *)screenShots { CGSize imageSize = [[UIScreen mainScreen] bounds].size; if (NULL != &UIGraphicsBeginImageContextWithOptions) { UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); } else { UIGraphicsBeginImageContext(imageSize); } CGContextRef context = UIGraphicsGetCurrentContext(); for (UIWindow * window in [[UIApplication sharedApplication] windows]) { if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) { CGContextSaveGState(context); CGContextTranslateCTM(context, [window center].x, [window center].y); CGContextConcatCTM(context, [window transform]); CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y); [[window layer] renderInContext:context]; CGContextRestoreGState(context); } } UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(image, self, nil, nil); NSLog(@"Suceeded!"); return image; }
UIGraphicsBeginImageContextWithOptions(self.zoomScrollView.size , NO, 1);
[self.zoomScrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *uiImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//把截图保存到相册里
下面总结了几种截图 和图片合成的方法
//第二种多图片绘图方法 高清 -(UIImage *)getSubImage3 { CGSize size = self.img_content.image.size; CGFloat scale = self.img_content.image.size.width/self.img_content.frame.size.width; CGSize canvasSize = size; UIGraphicsBeginImageContext(canvasSize); //Draw image2 [self.img_content.image drawInRect:CGRectMake(0, 0, canvasSize.width, canvasSize.height)]; [self.texiaoView.subviews enumerateObjectsUsingBlock:^(UIImageView * imageview, NSUInteger idx, BOOL *stop) { if ([[imageview class] isSubclassOfClass:[UIImageView class]]) { // CGSize canvasSize2; UIImage * image = imageview.image; CGRect frame = imageview.frame; CGPoint offset = frame.origin; offset.x = scale * offset.x; offset.y = scale * offset.y; CGSize drawsize; drawsize.width = scale*image.size.width; drawsize.height =scale* image.size.height; [image drawInRect:CGRectMake(offset.x, offset.y, drawsize.width, drawsize.height)]; } }]; UIImage *resultImage=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resultImage; } //用绘图的模式获得图片 模糊 -(UIImage *)getSubImage2{ CGSize size = self.img_content.frame.size; CGSize canvasSize = size; CGPoint offset1; offset1.x = (canvasSize.width - size.width) / 2.0f; offset1.y = (canvasSize.height - size.height) / 2.0f; UIGraphicsBeginImageContextWithOptions( canvasSize, NO, 1); [[self.img_content.image resize:size] drawAtPoint:offset1 blendMode:kCGBlendModeNormal alpha:1.0f]; [self.texiaoView.subviews enumerateObjectsUsingBlock:^(UIImageView * imageview, NSUInteger idx, BOOL *stop) { if ([[imageview class] isSubclassOfClass:[UIImageView class]]) { // CGSize canvasSize2; UIImage * image = imageview.image; CGRect frame = imageview.frame; CGPoint offset = frame.origin; // canvasSize2.width = fmaxf(size.width, image.size.width); // canvasSize2.height = fmaxf(size.height, image.size.height ); [image drawAtPoint:offset blendMode:kCGBlendModeNormal alpha:1.0f]; } }]; UIImage * result = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return result; } //用截图的模式获得图片 有模糊 -(UIImage *)getSubImage{ // self.originalImage = self.showImgView.image; UIGraphicsBeginImageContext(self.BgView.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); UIRectClip(CGRectMake(0, 0, self.BgView.width, self.BgView.height)); [self.BgView.layer renderInContext:context]; UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage; }