合并并保存两个 UIImageView
我的项目有两个 UIImages
,一个名为 imageView
,另一个名为 Birdie
。
- (UIImage *)addImage:(UIImage *)imageView toImage:(UIImage *)Birdie {
UIGraphicsBeginImageContext(imageView.size);
// Draw image1
[imageView drawInRect:CGRectMake(0, 0, imageView.size.width, imageView.size.height)];
// Draw image2
[Birdie drawInRect:CGRectMake(0, 0, Birdie.size.width, Birdie.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
-(void)captureScreen{
UIImageWriteToSavedPhotosAlbum(resultingImage, nil, nil, nil);
}
这是我的代码,captureScreen
按钮是保存图像的。它不起作用,因为 resultingImage
未声明,但我对 Xcode 还很陌生,所以我不知道如何解决这个问题。
非常感谢!
My project has two UIImages
, one named imageView
and one named Birdie
.
- (UIImage *)addImage:(UIImage *)imageView toImage:(UIImage *)Birdie {
UIGraphicsBeginImageContext(imageView.size);
// Draw image1
[imageView drawInRect:CGRectMake(0, 0, imageView.size.width, imageView.size.height)];
// Draw image2
[Birdie drawInRect:CGRectMake(0, 0, Birdie.size.width, Birdie.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
-(void)captureScreen{
UIImageWriteToSavedPhotosAlbum(resultingImage, nil, nil, nil);
}
This is my code, the captureScreen
button is to save the image. It's not working because resultingImage
is undeclared, but I'm pretty new to Xcode so I don't know how to fix this.
Many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是全局变量,其范围仅限于
- (UIImage *)addImage:(UIImage *)imageView toImage:(UIImage *)Birdie
方法,您必须调用此方法并使用此方法返回的对象方法。蒂姆,
您应该记住一点,我们不能直接调用“drawRect”方法。
系统会调用它。
所以这里你应该使用 UIImage 可用的其他方法。
您可以使用“imageNamed:”方法......
Is not a global variable its scope is limited to only
- (UIImage *)addImage:(UIImage *)imageView toImage:(UIImage *)Birdie
method you have to call this method and use returned object by this method.Tim,
one point you should remember tht we must not call 'drawRect' method directly.
It would be called by the system.
So here you should use other methods available for UIImage.
you can use 'imageNamed:' method....
你可以做这样的事情。
将此
-(void)captureScreen:
方法覆盖为-(void)captureScreen:(UIImage*)imageToSave
,然后在您的按钮操作中,例如
- (IBAction)myButton: (id)发件人{
[self captureScreen:[self addImage:imageViewImage toImage:BirdieImage]]
}
You can do something like this.
Override this
-(void)captureScreen:
method to-(void)captureScreen:(UIImage*)imageToSave
then in your button action like
- (IBAction)myButton:(id)sender{
[self captureScreen:[self addImage:imageViewImage toImage:BirdieImage]]
}