UIImageJPEGRepresentation zabierająca ogromną pamięć
Próbuję rozwiązać ten problem, ale nie udało mi się zrobić po wszystkim, co znalazłem w systemie operacyjnym lub Google. Problem polega na tym, że podczas konwersjiUIImage
doNSData
za pomocąUIImageJPEGRepresentation
lubUIImagePNGRepresentation
zwiększa rozmiar pamięci do 30 MB (uwierz mi lub nie).
Oto mój kod
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
[self writeImageThumbnailToFolder:image];
[self writeImageHomeViewThumbnailToFolder:image];
Próbowałem również zastosować następujące rozwiązanieUIImageJPEGRepresentation - wydanie wydania pamięci
1- Używane @auto-release
2- zrobione pngData = zero;
ale wciąż stoi przed tym problemem pamięci.
EDYTOWAĆ Myślę, że nie jestem w stanie przekazać mojego problemu. W porządku, jeśliUIImageJPEGRepresentation
biorąc ogromną pamięć,ale pamięć powinna powrócić do wcześniejszej pozycji po zapisaniu tego obrazu. Mam nadzieję, że pomoże ci to szczegółowo.