将 UIImageview 覆盖在 UIImageview 上保存

发布于 2024-11-03 02:10:10 字数 1125 浏览 3 评论 0原文

我正在尝试合并两个 UIImageView。第一个 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;
}

但我只收到此代码的错误! 提前致谢!

I'm trying to merge two UIImageViews. The first UIImageView (theimageView) is the background, and the second UIImageView (Birdie) is an image overlaying the first UIImageView. You can load the first UIImageView from a map or take a picture. After this you can drag, rotate and scale the second UIImageView over the first one. I want the output (saved image) to look the same as what I see on the screen.

I got that working, but I get borders and the quality and size are bad. I want the size to be the same as that of the image which is chosen, and the quality to be good. Also I get a crash if I save it a second time, right after the first time.

Here is my current code:

//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;
}

But I only get errors with this code!
Thanks in advanced!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文