我正在开发一个应用程序,当用户从相机拍照时,我必须逐个缝合多个图像。
这是我用来合并两张图片的内容。
[self performSelector:@selector(joinImages:secondImage:) withObject:firstimage withObject:imageCaptured];
- (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//Joins 2 UIImages together, stitching them horizontally
CGSize size = CGSizeMake(im1.size.width+im2.size.width, im2.size.height);
UIGraphicsBeginImageContext(size);
CGPoint image1Point = CGPointMake(0, 0);
[im1 drawAtPoint:image1Point];
CGPoint image2Point = CGPointMake(im1.size.width,0);
[im2 drawAtPoint:image2Point];
UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
firstimage=finalImage;// final images updated everytime
[pool release];
return finalImage;
}
但是当我在iPhone上运行它时,我收到内存警告,它适用于iPod。
如果是iPhone,还会裁剪图像。
我可以采取任何措施来解决此问题。
谢谢..
答案 0 :(得分:1)
你可以这样做。
- (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2
{
@autoreleasepool
{
//Joins 2 UIImages together, stitching them horizontally
CGSize size = CGSizeMake(im1.size.width+im2.size.width, im2.size.height);
UIGraphicsBeginImageContext(size);
CGPoint image1Point = CGPointMake(0, 0);
[im1 drawAtPoint:image1Point];
CGPoint image2Point = CGPointMake(im1.size.width,0);
[im2 drawAtPoint:image2Point];
UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
firstimage=finalImage;// final images updated everytime
return finalImage;
}
}
希望这对你有用。
答案 1 :(得分:0)
[self joinImages:firstimage secondImage:secondImage];
- (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//Joins 2 UIImages together, stitching them horizontally
CGSize size = CGSizeMake(im1.size.width+im2.size.width, im2.size.height);
UIGraphicsBeginImageContext(size);
CGPoint image1Point = CGPointMake(0, 0);
[im1 drawAtPoint:image1Point];
CGPoint image2Point = CGPointMake(im1.size.width,0);
[im2 drawAtPoint:image2Point];
UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
firstimage=finalImage;// final images updated everytime
[pool release];
return finalImage;
}