我想将图像保存到沙盒...当我保存许多图像时,我的应用程序经常崩溃并发出 MemoryWarning .....
这是代码:
-(void)saveCurrentLine:(NSDictionary*)lineInfo
{
UIImage* saveImage=[lineInfo objectForKey:@"saveImage"];
NSString* savePath=[lineInfo objectForKey:@"SPN"];
NSLog(@"The savePath is :%@",savePath);
NSString* docs=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSString *pngPath = [docs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@",noteBookName,savePath]];
NSLog(@"%@",pngPath);
[UIImagePNGRepresentation(saveImage) writeToFile:pngPath atomically:YES];
UIImage* saveJPG=[lineInfo objectForKey:@"saveImage"];
UIImage* saveJIV=[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@IV",pngPath]];
NSString *pngPathS = [docs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@Scan/%@",noteBookName,savePath]];
[UIImageJPEGRepresentation([self addImage:[self scaleToSize:saveJIV size:CGSizeMake(256, 192)] toImage:[self scaleToSize:saveJPG size:CGSizeMake(256, 192)]], 1.0) writeToFile:pngPathS atomically:NO];
NSLog(@"line save over and [saveJPG count] is %d [saveJIV count] is %d [lineInfo count] is %d",[saveJPG retainCount],[saveJIV retainCount],[lineInfo retainCount]);
}
我发现saveJPG和saveJIV没有释放,我不能释放它们......我怎样才能让它们释放????
此功能的所有方法:
-(void)ChangeCanvasTo:(NSNotification*)CanvasInfo
{
self.layer.opacity=1.0;
savePageName=[NSString stringWithFormat:@"%@",PageName];
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSDictionary *currentLine=[[NSDictionary alloc] initWithObjectsAndKeys:saveImage,@"saveImage",savePageName,@"SPN",nil];
[NSThread detachNewThreadSelector:@selector(saveCurrentLine:) toTarget:self withObject:currentLine];
NSString *pngPath=[[CanvasInfo userInfo] objectForKey:@"PageName"];
PageName=pngPath;
NSLog(@"will change to %@",PageName);
NSString* docs=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
UIImage *resumeCanvas=[[UIImage alloc] initWithContentsOfFile:[docs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@",noteBookName,PageName]]];
drawStep=RELOAD;
curImage=resumeCanvas;
[curImage retain];
[self setNeedsDisplay];
[resumeCanvas release];
[currentLine release];
}
-(void)saveCurrentLine:(NSDictionary*)lineInfo
{
UIImage* saveImage=[lineInfo objectForKey:@"saveImage"];
NSString* savePath=[lineInfo objectForKey:@"SPN"];
NSLog(@"The savePath is :%@",savePath);
NSString* docs=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSString *pngPath = [docs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@",noteBookName,savePath]];
NSLog(@"%@",pngPath);
[UIImagePNGRepresentation(saveImage) writeToFile:pngPath atomically:YES];
UIImage* saveJPG=[lineInfo objectForKey:@"saveImage"];
UIImage* saveJIV=[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@IV",pngPath]];
NSString *pngPathS = [docs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@Scan/%@",noteBookName,savePath]];
[UIImageJPEGRepresentation([self addImage:[self scaleToSize:saveJIV size:CGSizeMake(256, 192)] toImage:[self scaleToSize:saveJPG size:CGSizeMake(256, 192)]], 1.0) writeToFile:pngPathS atomically:NO];
NSLog(@"line save over and [saveJPG count] is %d [saveJIV count] is %d [lineInfo count] is %d",[saveJPG retainCount],[saveJIV retainCount],[lineInfo retainCount]);
}