FROM : Gregory Weston
DATE : Sun Jun 04 22:07:13 2006
> I can find a couple of sample pieces to do this, but they are part of
> something more complex and I cannot determine what I need.
> So how do I save an NSImage instance (obtained from an NSURL) into a
> file, .tif or jpeg or whatever? Assume I already have a file path for
> the file.
If your image has an NSBitmapImageRep it's dead simple. Get the image
rep and send it
- (NSData *)representationUsingType:(NSBitmapImageFileType)
storageType properties:(NSDictionary *)properties.
The first argument can be one of (at least) NSBMPFileType,
NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType. Then
do what you like with the NSData you end up getting.
If you don't have a bitmap ImageRep, or don't care to go to the
effort to find out if you do, you can make one:
NSBitmapImageRep* bm = [NSBitmapImageRep imageRepWithData:[image
TIFFRepresentation]];
DATE : Sun Jun 04 22:07:13 2006
> I can find a couple of sample pieces to do this, but they are part of
> something more complex and I cannot determine what I need.
> So how do I save an NSImage instance (obtained from an NSURL) into a
> file, .tif or jpeg or whatever? Assume I already have a file path for
> the file.
If your image has an NSBitmapImageRep it's dead simple. Get the image
rep and send it
- (NSData *)representationUsingType:(NSBitmapImageFileType)
storageType properties:(NSDictionary *)properties.
The first argument can be one of (at least) NSBMPFileType,
NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType. Then
do what you like with the NSData you end up getting.
If you don't have a bitmap ImageRep, or don't care to go to the
effort to find out if you do, you can make one:
NSBitmapImageRep* bm = [NSBitmapImageRep imageRepWithData:[image
TIFFRepresentation]];
| Related mails | Author | Date |
|---|---|---|
| Graham | Jun 4, 20:52 | |
| Paul Lynch | Jun 4, 21:04 | |
| Nick Zitzmann | Jun 4, 21:04 | |
| Gregory Weston | Jun 4, 22:07 | |
| Michael B Johnson | Jun 5, 00:56 | |
| Ron Fleckner | Jun 5, 01:19 |






Cocoa mail archive

