UIImage decodes image data, so it can be edited and displayed, therefore
UIImageWriteToSavedPhotosAlbum([UIImage imageWithContentsOfFile:[NSData dataWithContentsOfFile:[self getImagePath]]], self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
First decodes the image, and then encodes it using the UIImageWriteToSavedPhotosAlbum method.
Instead, you should use ALAssetsLibrary / writeImageDataToSavedPhotosAlbum: metadata: completionBlock:, something like this:
ALAssetsLibrary *assetLib = [[[ALAssetsLibrary alloc] init] autorelease]; [assetLib writeImageDataToSavedPhotosAlbum:[self getImagePath] metadata:nil completionBlock:nil];
You can also transfer metadata and a call termination unit.
EDIT:
To get an image:
[info objectForKey:@"UIImagePickerControllerOriginalImage"] contains a decoded UIImage selected from UIImagePickerController . You should use instead
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
Using assetURL , you can get an ALAsset for it using the ALAssetsLibrary / assetForURL: resultBlock: failureBlock: method :
ALAssetsLibrary *assetLib = [[[ALAssetsLibrary alloc] init] autorelease]; [assetLib assetForURL:assetURL resultBlock:resultBlock failureBlock:failureBlock];
Now you can get the unchanged NSData of this image:
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset){ ALAssetRepresentation *assetRep = [asset defaultRepresentation]; long long imageDataSize = [assetRepresentation size]; uint8_t* imageDataBytes = malloc(imageDataSize); [assetRepresentation getBytes:imageDataBytes fromOffset:0 length:imageDataSize error:nil]; NSData *imageData = [NSData dataWithBytesNoCopy:imageDataBytes length:imageDataSize freeWhenDone:YES];
I may have made some mistakes in the code, but the steps are listed above. If something doesnβt work correctly or if you want to make it a little more efficient, there are many examples of things like reading NSData from ALAsset on stackoverflow or other sites.