相关疑难解决方法(0)

调整UIImage的大小而不将其完全加载到内存中?

我正在开发一个应用程序,用户可能会尝试加载非常大的图像.这些图像首先在表格视图中显示为缩略图.我的原始代码会在大图像上崩溃,因此我将其重写为首先将图像直接下载到磁盘.

是否有一种已知的方法来调整磁盘上的映像大小而不通过它完全加载到内存中UIImage?目前,我想要使用的类别来调整UIImage详见这里,但我的应用程序崩溃的尝试缩略图非常大的图像(如,例如, -警告,庞大的图像).

cocoa-touch objective-c uiimage ios

22
推荐指数
1
解决办法
1万
查看次数

UIImageJPEGRepresentation占用大量内存

我试图找出这个问题,但在做了我在OS或谷歌上发现的所有事情后失败了.问题是,当我转换UIImageNSData使用UIImageJPEGRepresentationUIImagePNGRepresentation它将内存大小增加到30Mb(相信我或不相信).
这是我的代码

myImage= image;
LoginSinglton*loginObj = [LoginSinglton sharedInstance];
NSError *error;
NSData *pngData = UIImageJPEGRepresentation(image, scaleValue); //scaleVale is 1.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory

self.imageCurrentDateAndTime =[self getTimeAndDate];
 self.filePathAndDirectory = [documentsPath stringByAppendingPathComponent:@"Photos Dir"];

NSLog(@"Documents path %@",self.filePathAndDirectory);
if (![[NSFileManager defaultManager] createDirectoryAtPath:self.filePathAndDirectory
                               withIntermediateDirectories:NO
                                                attributes:nil
                                                     error:&error])
{
    NSLog(@"Create directory error: %@", error);
}
self.imageName= [NSString stringWithFormat:@"photo-%@-%@.jpg",loginObj.userWebID,self.imageCurrentDateAndTime];
 NSString *filePath = [self.filePathAndDirectory stringByAppendingPathComponent:self.imageName];

[pngData writeToFile:filePath atomically:YES]; //Write the file …
Run Code Online (Sandbox Code Playgroud)

objective-c uiimage ios

4
推荐指数
1
解决办法
6480
查看次数

标签 统计

ios ×2

objective-c ×2

uiimage ×2

cocoa-touch ×1