saving images on panther
saving images on panther
- Subject: saving images on panther
- From: Cornelius Jaeger <email@hidden>
- Date: Thu, 12 May 2005 12:17:22 +0200
hi all
i have a category on nsimage to save to a path directly.
this works on tiger, no worries, but fails on panther.
the files saved are corrupted somehow.
can someone help me with this, i don't see an error in the code:
@implementation NSImage (NSImage_Additions)
+ (NSDictionary *) fileRepresentationDictionary
{
return [NSDictionary dictionaryWithObjectsAndKeys:
NSTIFFFileType, @"tif",
NSTIFFFileType, @"tiff",
NSBMPFileType, @"bmp",
NSJPEGFileType, @"jpg",
NSJPEGFileType, @"jpeg",
NSGIFFileType, @"gif",
NSJPEGFileType, @"png",
nil];
}
+ (NSBitmapImageFileType)fileTypeForPath:(NSString *)path
{
NSString * ending = [[[path lastPathComponent] pathExtension]
lowercaseString];
return (NSBitmapImageFileType)[[NSImage
fileRepresentationDictionary] valueForKey:ending];
}
- (NSRect) rect
{
return NSMakeRect(0,0,[self size].width, [self size].height);
}
- (void) writeToFile:(NSString *)filepath atomically:(BOOL)flag
{
NSLog(@"writing image: %@", filepath);
[self lockFocus];
NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]
initWithFocusedViewRect:[self rect]];
[self unlockFocus];
NSBitmapImageFileType ft = [NSImage fileTypeForPath:filepath];
NSData * data = [rep representationUsingType:ft properties:nil];
NSFileManager * fm = [NSFileManager defaultManager];
[data writeToFile:filepath atomically:flag];
[rep release];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden