• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
saving images on panther
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: saving images on panther
      • From: "Sean McBride" <email@hidden>
  • Prev by Date: CoreData could not fulfill a fault
  • Next by Date: Re: Add metadata to my files for Spotlight
  • Previous by thread: Re: CoreData could not fulfill a fault
  • Next by thread: Re: saving images on panther
  • Index(es):
    • Date
    • Thread