gpt4 book ai didi

iphone - 拼接图像时收到内存警告

转载 作者:行者123 更新时间:2023-11-29 13:02:09 26 4
gpt4 key购买 nike

我正在开发一个应用程序,当用户从相机拍摄照片时,我必须一张一张地拼接多张图像。

这就是我用来合并两张图片的方法。

[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,图像也会被裁剪。

我能做些什么来解决这个问题。

谢谢..

最佳答案

你可以这样做。

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

希望这对你有用。

关于iphone - 拼接图像时收到内存警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19515247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com