• 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
Trying to write icon data to file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to write icon data to file


  • Subject: Trying to write icon data to file
  • From: Kevin Walzer <email@hidden>
  • Date: Fri, 13 Mar 2009 10:57:08 -0400
  • Organization: WordTech Communications LLC

I'm putting together some code that will write an icon file (obtained via NSWorkspace) to a gif.

I had prototyped the code with a simple command-line tool with hard-coded values for file sources, destinations, and image sizes. However, when I try to abstract the code, I am now getting weird error messages:

<Error>: CGImageCreate: invalid image size: 0 x 0.
2009-03-13 10:40:48.805 Wish[20760:10b] Could not create CGImageRef - w:0, h:0, bps:8, bpp:32, bpr:512, alpha:0x1, cSpace:NSCalibratedRGBColorSpace, hasAlpha:1, isPlanar:0
Fri Mar 13 10:40:48 Macintosh.local Wish[20760] <Error>: CGImageDestinationFinalize image destination does not have enough images
CGImageDestinationFinalize failed for output type 'com.compuserve.gif'
objc[20760]: FREED(id): message release sent to freed object=0x466430



The basic code is below:

-(int) makeIcon: (NSString *) filePath imagewidth: (float) width imageheight: (float)height outputfile:(NSString *)imagePath {

  NSApplicationLoad();

  //set up autorelease pool
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];


//retrieve the icon NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:filePath];

//get bitmap representation of icon
NSBitmapImageRep *resizeicon = (NSBitmapImageRep *)[icon bestRepresentationForDevice:nil];


  //set the icon size
  [resizeicon setSize:NSMakeSize(width, height)];
  [resizeicon  setPixelsWide: width];
  [resizeicon setPixelsHigh:height];


//convert icon to gif, write to file
[[resizeicon representationUsingType:NSGIFFileType properties:nil] writeToFile:imagePath atomically:NO];



//release memory [icon release]; [resizeicon release]; [pool release]; return 0;

}

The prototype code, below, actually works as designed, so I'm not sure what the problem is. Any advice is appreciated.

#import <Cocoa/Cocoa.h>

int main (int argc, char *argv[]) {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:@"/Applications/AppKiDo.app"];

NSBitmapImageRep *resizeicon = (NSBitmapImageRep *)[icon bestRepresentationForDevice:nil];

[resizeicon setSize:NSMakeSize(48.0, 48.0)];

[resizeicon setPixelsWide:48.0];


[resizeicon setPixelsHigh:48.0];

[[resizeicon representationUsingType:NSGIFFileType properties:nil] writeToFile:@"/Users/kevin/Desktop/bar.gif" atomically:NO];

[pool release];

return 0;

}

Thanks....

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Trying to write icon data to file
      • From: "Adam R. Maxwell" <email@hidden>
  • Prev by Date: Re: [CA] zPosition + mask + animation = no animation
  • Next by Date: Re: Performance problem with GC enabled
  • Previous by thread: Re: cocoa file APIs
  • Next by thread: Re: Trying to write icon data to file
  • Index(es):
    • Date
    • Thread