Re-saving a JPEG without increasing file size or causing artefacts?
Re-saving a JPEG without increasing file size or causing artefacts?
- Subject: Re-saving a JPEG without increasing file size or causing artefacts?
- From: Keith Blount <email@hidden>
- Date: Tue, 22 Feb 2005 08:26:20 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello,
In my program I need to take an image, rescale it, and
save it back to disk. The scaling isn't a problem, but
it seems more difficult than it should be to resave
the image without either causing a massive increase in
file size, or losing a lot of data.
For instance, if I have dragged a .jpg file into my
app which is viewed as an NSImage, as I understand it,
this is how I should save it back to disk:
NSBitmapRep *rep = [[image representations]
objectAtIndex:0];
NSDictionary *compression = [NSDictionary
dictionaryWithObject:[NSNumber numberWithFloat:1.0];
NSData *data = [rep
representationUsingType:NSJPEGFileType
properties:compression
forKey:NSImageCompressionFactor]];
//... writeToFile the data here
I have played with the compression factor, and what I
find is this:
- if I set the factor to 1.0 and resave the file, the
file size pretty much doubles - even if the image has
been scaled down. I don't understand this, as I would
have thought 1.0 would just save it at the same
quality as the original file, which shouldn't cause
any change in file size.
- if I set the fact to anything below 1.0 (eg. 0.75),
if I scale the image up and down several times, the
quality is lost and artefacts appear.
Does anyone know of a way of resaving images to file
without causing weird changes in their quality or file
size?
Many thanks for any help - I know this has been asked
before, but on searching the archives it seems that
most of the questions haven't been resolved.
All the best,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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