我有不同的肖像和风景图像,我从 Document 目录中获取图像,它们总共有 62 张图像。31 幅 1015x745 尺寸的横向图像和 31 幅 751x1024 尺寸的纵向图像。所有图像都加载在模拟器上,但是当我在设备中运行相同的代码时,应用程序崩溃了。它仅在横向图像上加载肖像。
int porWidth = 768, lanWidth = 1024;
int i=0;
for (CatalogIndividuals *cat in self.array)
{
UIImageView *imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(porWidth*i +5, 0, 757, 964)] autorelease];
imageView1.tag = porImage+i;
NSString *fullPath =[self.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",cat.portraitImage]];
imageView1.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:[fullPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"]]];
imageView1.contentMode = UIViewContentModeScaleAspectFit;
UIImageView *imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(lanWidth*i +5, 0, 1015, 620)] autorelease];
imageView2.tag = lanImage+i;
NSString *tempPath = [self.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",cat.landscapImage]];
NSString *str = [tempPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
NSLog(@"imageView1 fullPath = %@",str);
imageView2.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:str]];}
我认为存在一些内存泄漏问题。如果有人有任何解决方案,请提供帮助。