我正在开发一个应用程序,当用户从相机拍照时,我必须一张一张地拼接多张图像。
这就是我用来合并两个图像的方法。
[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,图像也会被裁剪。
我可以做任何事情来解决这个问题。
谢谢..