UIGestureRecognizer通过后如何保存UIImageView?
我有一个应用程序与2 UIImageView被铺设在对方。 我有backgroundImg和FrontImg。 frontImg可以:旋转,移动,通过UIGestureRecognizers进行缩放。
当我想保存我的UIImages时,我将它们合并,但是他们被保存,好像他们从来没有碰过一样。
有谁知道如何解决这个问题?
这是我的保存方法:UIGraphicsBeginImageContext(self.backgroundImg.image.size);
CGRect rect = CGRectMake(0, 0, self.backgroundImg.image.size.width, self.backgroundImg.image.size.height); self.frontImg.contentMode = UIViewContentModeScaleAspectFit; [self.backgroundImg.image drawInRect:rect]; [self.frontImg.image drawInRect:rect]; UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); //[imageView3 setImage:resultingImage]; UIGraphicsBeginImageContextWithOptions(self.backgroundImg.bounds.size, NO,0.0); [self.backgroundImg.image drawInRect:CGRectMake(0, 0, self.backgroundImg.frame.size.width, self.backgroundImg.frame.size.height)]; //UIImage *SaveImage = UIGraphicsGetImageFromCurrentImageContext(); //UIImage *resultingImage = [self mergeImage:self.backgroundImg.image withImage:self.frontImg.image]; UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(resultingImage, self,@selector(image:didFinishSavingWithError:contextInfo:), nil);
这些是我的手势function:
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{ CGPoint translation = [recognizer translationInView:self.view]; recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); [recognizer setTranslation:CGPointMake(0, 0) inView:self.view]; } -(IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer { recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale); recognizer.scale =1; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return ![gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]; } -(IBAction)handleRotate:(UIRotationGestureRecognizer *)recognizer { recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation); self.frontImg.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation); recognizer.rotation = 0; }
希望可以有人帮帮我。
克。 乐华
您的正面图像不是在视图中的坐标,比例等处绘制的。 您使用与背景相同的矩形(0,0,backgroundWidth,backgroundHeight)绘制它。 你需要确保当你把它绘制到graphics上下文时,你会得到正确的位置,大小和比例。
如果两个图像都包含在相同的视图中,则可以截取该视图。 这篇文章应该帮助你: http : //ios-dev-blog.com/how-to-create-uiimage-from-uiview/