You can get the source binary file with the photo below and save it in the target file.
+ (NSData *)photoAssetRawData:(ALAsset *)photoAsset error:(NSError **)error { ALAssetRepresentation *rep = photoAsset.defaultRepresentation; NSMutableData *data = [NSMutableData new]; long long offset = 0; uint8_t dataBuffer[PHOTO_READ_CHUNK_SIZE]; NSError *internalError; do { NSUInteger readByteLength = [rep getBytes:dataBuffer fromOffset:offset length:sizeof(dataBuffer) error:&internalError]; if(internalError != nil) { if(error != NULL) { *error = internalError; } return nil; } offset += readByteLength; [data appendBytes:(void*)dataBuffer length:readByteLength]; } while (offset < rep.size); return data; }
One thing to keep in mind, this raw data did not apply any default filter gallery for iOS filters. If you want this filter to be applied, you should get this XMP-enabled filter from the [ALAssetRepresentation] metadata and create filters using [CIFilter filterArrayFromSerializedXMP: inputImageExtent: error:], then apply them at full resolution, finally save this processed image as JPEG or PNG to file.
The following shows how to apply these filters.
+ (CGImageRef)applyXMPFilter:(ALAsset *)asset{ ALAssetRepresentation *rep = [asset defaultRepresentation]; CGImageRef imageRef = [rep fullResolutionImage]; NSString *adjustmentXMP; NSData *adjustmentXMPData; NSError *__autoreleasing error = nil; NSArray *filters=nil; CGRect extend = CGRectZero;
source share