在UIImageview上覆盖UIImageview保存

时间:2011-04-23 23:24:05

标签: iphone xcode merge uiimageview save

我正在尝试合并两个UIImageViews。第一个UIImageView(theimageView)是背景,第二个UIImageView(Birdie)是覆盖第一个UIImageView的图像。您可以从地图加载第一个UIImageView或拍照。在此之后,您可以在第一个UIImageView上拖动,旋转和缩放第二个UIImageView。我希望输出(保存的图像)看起来与我在屏幕上看到的相同。

我得到了它的工作,但我得到了边界,质量和尺寸都很糟糕。我希望尺寸与所选图像的尺寸相同,并且质量要好。如果我第一次保存第二次,我也会崩溃。

这是我目前的代码:

//save actual design in photo library
- (void)captureScreen {
    UIImage *myImage = [self addImage:theImageView ToImage:Birdie];
    [myImage retain];
    UIImageWriteToSavedPhotosAlbum(myImage, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), self); 
}


- (UIImage*) addImage:(UIImage*)theimageView toImage:(UIImage*)Birdie{
   CGSize size = CGSizeMake(theimageView.size.height, theimageView.size.width);
   UIGraphicsBeginImageContext(size);

   CGPoint pointImg1 = CGPointMake(0,0);
   [theimageView drawAtPoint:pointImg1 ];

   CGPoint pointImage2 = CGPointMake(0, 0);
   [Birdie drawAtPoint:pointImage2 ];

   UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();

   return result;
}

但是这个代码只会出错! 先谢谢!