Re: NSImage - Converting image formats
Re: NSImage - Converting image formats
- Subject: Re: NSImage - Converting image formats
- From: Jonathan Hendry <email@hidden>
- Date: Mon, 25 Jun 2001 22:39:14 -0500
On Monday, June 25, 2001, at 07:31 , Ivan Salina Fernandes wrote:
I'm trying to convert PDF images into Jpeg images. I used
TIFFRepresentation in a NSBitmapImageRep, but I can't change the
compression. Can anybody help me to change this parameters?
I think you want to use NSBitmapImageRep's method
- (NSData
*)representationUsingType:(NSBitmapImageFileType)storageType
properties:(NSDictionary *)properties;
with NSJPEGFileType as the storageType.
If you want an actual jpeg file, then I don't think you
want to use - TIFFRepresentation.
eg,
//I haven't compiled or run this, so you may have to tweak it.
NSBitmapImageRep *imageRep;
NSDictionary *propertyDict;
NSNumber *compressionFactor;
NSData *jpgData;
// The compression factor is a float between 1.0 and 255.0,
// with larger numbers providing greater compression and
// more distortion. See the HTML docs for NSBitmapImageRep.
compressionFactor = [NSNumber numberWithFloat:10.0];
propertyDict = [NSDictionary dictionaryWithObject:compressionFactor
forKey:NSImageCompressionFactor];
jpgData = [imageRep representationUsingType:NSJPEGFileType
properties:propertyDict];
[jpgData writeToFile:@"foo.jpg" atomically:NO];