本当にありがとう、私はテストしました、そしてそれは本当です。これは私の問題の概要です: デバイスに 132 個の画像 (~300 kb / 1 画像) があります。私の目的は、2 つの画像を 1 つの大きな画像にマージすることです (水平方向に並べて表示)。これが私がすることです :
int index = 1;
for(int i = 1;i <= 132;i++)
{
if(i % 2 == 0 && i > 1)
{
NSString *file = [NSString stringWithFormat:@"%@img_%d.jpg",path2,index];
NSLog(@"index %d",index);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *data;
NSString *filename1 = [NSString stringWithFormat:@"originimg_%d.jpg",i];
NSString *filename2 = [NSString stringWithFormat:@"originimg_%d.jpg",i + 1];
NSString *file1 = [[NSBundle mainBundle] pathForResource:filename1 ofType:nil];
NSString *file2 = [[NSBundle mainBundle] pathForResource:filename2 ofType:nil];
UIImage *image1 = [[UIImage alloc]initWithContentsOfFile:file1];
UIImage *image2 = [[UIImage alloc]initWithContentsOfFile:file2];
UIImage *image = [self combineImages:image1 toImage:image2];
data = UIImageJPEGRepresentation(image, 0.7);
[data writeToFile:file atomically:NO];
[image1 release];
image1 = nil;
[image2 release];
image2 = nil;
[pool drain];
pool = nil;
[file release];
file = nil;
index++;
}
}
および2つの画像を結合する機能
-(UIImage *)combineImages:(UIImage *)image1 toImage:(UIImage *)image2
{
CGSize size;
size= CGSizeMake(768 * 2, 1024);
UIGraphicsBeginImageContext(size);
// Draw image1
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
// Draw image2
[image2 drawInRect:CGRectMake(image1.size.width, 0, image2.size.width, image2.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage ;
}
- それが私のやり方ですが、インストルメント (割り当て) で実行すると、303.4 mb かかります:( 。より良い方法を提案できますか?