Knowledge Base Nr: 00340 imagesupp.m - http://www.swe-kaiser.de
Downloads:
ObjC: dateihandling für images
- (void)saveImage:(UIImage*)image withName:(NSString*)sName
{
if (image != nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithString: sName] ];
CGFloat fQuality = [editSettingsImgCompress.text floatValue];
NSData* data = UIImageJPEGRepresentation(image, fQuality);
[data writeToFile:path atomically:YES];
}
}
- (UIImage*)loadImage:(NSString*)sName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithString: sName] ];
UIImage* image = [UIImage imageWithContentsOfFile:path];
return image;
}
- (void)deleteFile:(NSString*)sName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* file = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithString: sName] ];
[[NSFileManager defaultManager] removeItemAtPath:file error:nil];
}