So I have a UIImage that I load with [UIImage imageNamed]
. I then save that file to my documents directory. My issue is that the file originally had 240 resolution. When I retrieve the file from the Simulator's documents directory, it now has 72 resolution. How can I save it at the same resolution it was loaded as?
Here is how I load it:
UIImage * image = [UIImage imageNamed:@"halloween_big.jpg"]
CGContextRef context = CGBitmapContextCreate(
(void*) pixels,
image.size.width,
image.size.height,
8,
image.size.width * 4,
CGImageGetColorSpace(image.CGImage),
kCGImageAlphaPremultipliedLast
);
// get the image from the current context with our new pixels
CGImageRef imageRef = CGBitmapContextCreateImage( context );
image = [UIImage imageWithCGImage:imageRef];
EDIT - I have also tried by loading the image with just this and making no changes to the image:
UIImage *loaded = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"halloween_big" ofType:@"jpg"]];
Here is how I'm saving it:
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
EDIT - I get the same loss in resolution if I save the file as a PNG.
Just to be sure, the same thing happens if I change the quality paramter to UIImageJPEGRepresentation.