Re: How to write an NSImage to a JPEG file
Re: How to write an NSImage to a JPEG file
- Subject: Re: How to write an NSImage to a JPEG file
- From: Scott Anguish <email@hidden>
- Date: Fri, 22 Feb 2002 01:39:27 -0500
This is actually much easier than having to get down to OpenGL or even
QuickTime directly.
if you look at NSBitmapImageRep, there is a method there
- (NSData *)representationUsingType:(NSBitmapImageFileType)storageType
properties:(NSDictionary *)properties
and also
+ (NSData *)representationOfImageRepsInArray:(NSArray *)imageReps
usingType:(NSBitmapImageFileType)storageType properties:(NSDictionary
*)properties
Unfortunately, both of these are in the infamous 'description
forthcoming' category.
there are 5 different rep types available, including NSJPEGFileType and
NSPNGFileType..
As far as the propertiesDictionary goes, this is where you specify
things like Interlace, dithering and compression...
From the NSBitmapImageRep header file
NSImageCompressionMethod; // TIFF input/output (NSTIFFCompression in
NSNumber)
NSImageCompressionFactor; // TIFF/JPEG input/output (float in NSNumber)
NSImageDitherTransparency; // GIF output (BOOL in NSNumber)
NSImageRGBColorTable; // GIF input/output (packed RGB in NSData)
NSImageInterlaced; // PNG output (BOOL in NSNumber)
NSImageColorSyncProfileData; // TIFF input/output (NSData)
so, to save an NSImage, you get the rep (say with - (NSImageRep
*)bestRepresentationForDevice:(NSDictionary *)deviceDescription
, or representations)
and then get the data back for the specific file format above.
On Friday, February 22, 2002, at 12:51 AM, Craig Hagerman wrote:
Shayne,
I was wondering the same thing. No one else has given an answer yet
so...
I have just assumed that a cocoa NSImage is analogous to a Java Image
(awt
Image or swing IconImage) in that it is read only. If this is not so
then
someone PLEASE correct me. Given that I would assume that you must use
quicktime, or even OpenGL (but this seems like overkill) to write the
image.
I am just trying to understand this right now myself so I can't give any
concrete guidance. I am now looking through some sample code
(here for example: http://developer.apple.com/samplecode/)
that uses QuickTime in an effort to understand:
1. ...How to use it together with cocoa. (Use an NSMovie / NSMovieView
instead of an NSImage for starters.)
2. ...The quicktime API. Well not really understand (it is pretty HUGE)
but
more like get enough of a handle on it to be able to know how to do
simple
things.
Can anyone expand on this any more?
Craig Hagerman
on 2/21/02 3:11 PM, Shayne Packer at email@hidden wrote:
(resubmitted with a subject)
I need to write an NSImage out to a JPEG file.
In looking at the archives, I noticed that on 22 Oct 2001, sunnyvale
posted this question: "how to save a image in NSImage to pict format
file"
, with this comment: "I can save the NSImage to GIF or JPEG but not
PICT".
I've also seen other posts around this subject.
How can I save it to my new JPEG file?
Are there any settings for the compression quality?
thanks, Shayne
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.