I use this code get album pictures, and create file in the documents, but there will be Received memory warning, then crash。
Here is the code that I used. Can anyone tell me what did I do wrong?
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
NSLog(#"error occour =%#", [myerror localizedDescription]);
};
ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if (result!=NULL) {
//we can get all the things in the defaultRepresentation such as size info in UTI
}
//just fetching photos
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
//copy image to the path:Documents/DMS/Photo
ALAssetRepresentation *rep = [result defaultRepresentation];
NSString *tt = [rep filename];
NSString *fullPath = [pathPhoto stringByAppendingFormat:#"/%#",tt];
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]){
UIImage *image = [[UIImage alloc]initWithCGImage:[rep fullScreenImage]];
NSData *imageData = UIImagePNGRepresentation(image);
[image release];
[[NSFileManager defaultManager] createFileAtPath:fullPath contents:imageData attributes:nil];
NSLog(#"Creat image file fullPath================%#",fullPath);
//imageData = nil;
[imageData release];
}else{
NSLog(#"---------------------the image is Exist");
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock
libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop){
if (group == nil)
{
return;
}
if (group!=nil) {
[group enumerateAssetsUsingBlock:groupEnumerAtion];
}
NSLog(#"finish--------------------------------------------");
return;
};
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
[library release];
[pool release];
Since you say that you are using the code you posted inside of a loop, I suppose that what happens is that you app is being killed due to too many auto-released objects being allocated inside of the loop.
You could try using an autorelease pool:
for (...) {
#autoreleasepool {
<your code here>
}
}
so that the autorelease pool is cleaned up at each iteration (instead of growing all along the whole loop execution).
EDIT:
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
{
ALAssetRepresentation *rep = [result defaultRepresentation];
CGImageRef iref = [rep fullScreenImage];
NSString *tt = [rep filename];
if (iref)
{
UIImage *image = [UIImage imageWithCGImage:iref];
if(!image)
{
NSLog(#"---------------------the imageData is nil");
}
else
{
NSData *imageData = UIImagePNGRepresentation(image);
NSString *fullPath = [pathPhoto stringByAppendingFormat:#"/%#.png",tt];
NSLog(#"fullPath================%#",fullPath);
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath])
{
[[NSFileManager defaultManager] createFileAtPath:fullPath contents:imageData attributes:nil];
NSLog(#"Creat image file fullPath================%#",fullPath);
}
}
CGImageRelease(iref);
}
}
Related
In this code snippet the flow of program goes
out of for loop first then only goes inside the block
resultBlock:^(ALAsset *asset).
The code prints the NSLog at the bottom first then executes the block inside the loop. What's happening here?
ALAssetsLibrary *lib=[ALAssetsLibrary new];
_sizeOfSelectedImage=0;
for (int i=0; i<assets.count; i++) {
ALAsset *asset=assets[i];
FileOP *fileMgr=[[FileOP alloc]init];
NSString *baseDir=[fileMgr GetDocumentDirectory];
//STORING FILE INTO LOCAL
[lib assetForURL:asset.defaultRepresentation.url
resultBlock:^(ALAsset *asset){
ALAssetRepresentation *repr = [asset defaultRepresentation];
CGImageRef cgImg = [repr fullResolutionImage];
NSString *fname = repr.filename;
UIImage *img = [UIImage imageWithCGImage:cgImg];
NSData *data = UIImagePNGRepresentation(img);
[data writeToFile:[baseDir stringByAppendingPathComponent:fname]
atomically:YES];
//FOR LOCAL URL OF THE IMAGE
//NSString *imageURL = [baseDir stringByAppendingPathComponent:fname];
//UIImage *myImg =[UIImage imageWithContentsOfFile:imageURL];
//NSLog(#"%# URL OF IMAGE ",imageURL);
NSLog(#"Image %d has %d size",i,data.length);
_sizeOfSelectedImage +=data.length;
NSLog(#"%d is the size",_sizeOfSelectedImage);
}
failureBlock:^(NSError *error){
}];
}
NSLog(#"COPIED %lu FILE INTO LOCAL MEMORY AND TOTAL SIZE COPIED IS %d ",(unsigned long)assets.count,_sizeOfSelectedImage);
Method assetForURL:resultBlock:failureBlock: will execute the load of asset asynchronously. That's why we first have the bottom NSLog executed and then in Block. If you want it to be executed synchronously, do it like this:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0) ^{
ALAssetsLibrary *lib=[ALAssetsLibrary new];
_sizeOfSelectedImage=0;
dispatch_group_t group = dispatch_group_create();
for (int i=0;i<assets.count;i++) {
ALAsset *asset=assets[i];
FileOP *fileMgr=[[FileOP alloc]init];
NSString *baseDir=[fileMgr GetDocumentDirectory];
//STORING FILE INTO LOCAL
dispatch_group_enter(group);
[lib assetForURL:asset.defaultRepresentation.url
resultBlock:^(ALAsset *asset){
ALAssetRepresentation *repr = [asset defaultRepresentation];
CGImageRef cgImg = [repr fullResolutionImage];
NSString *fname = repr.filename;
UIImage *img = [UIImage imageWithCGImage:cgImg];
NSData *data = UIImagePNGRepresentation(img);
[data writeToFile:[baseDir stringByAppendingPathComponent:fname]
atomically:YES];
//FOR LOCAL URL OF THE IMAGE
//NSString *imageURL = [baseDir stringByAppendingPathComponent:fname];
//UIImage *myImg =[UIImage imageWithContentsOfFile:imageURL];
//NSLog(#"%# URL OF IMAGE ",imageURL);
NSLog(#"Image %d has %d size",i,data.length);
_sizeOfSelectedImage +=data.length;
NSLog(#"%d is the size",_sizeOfSelectedImage);
dispatch_group_leave(group);
}
failureBlock:^(NSError *error){
dispatch_group_leave(group);
}];
}
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
NSLog(#"COPIED %lu FILE INTO LOCAL MEMORY AND TOTAL SIZE COPIED IS %d ",(unsigned long)assets.count,_sizeOfSelectedImage);
dispatch_async(dispatch_get_main_queue(), ^{
// Do your call back on main thread here
});
});
Edit1: Enhanced answer from Ken
ALAssetsLibrary *lib=[ALAssetsLibrary new];
_sizeOfSelectedImage=0;
dispatch_group_t group = dispatch_group_create();
for (int i=0;i<assets.count;i++) {
ALAsset *asset=assets[i];
FileOP *fileMgr=[[FileOP alloc]init];
NSString *baseDir=[fileMgr GetDocumentDirectory];
//STORING FILE INTO LOCAL
dispatch_group_enter(group);
[lib assetForURL:asset.defaultRepresentation.url
resultBlock:^(ALAsset *asset){
ALAssetRepresentation *repr = [asset defaultRepresentation];
CGImageRef cgImg = [repr fullResolutionImage];
NSString *fname = repr.filename;
UIImage *img = [UIImage imageWithCGImage:cgImg];
NSData *data = UIImagePNGRepresentation(img);
[data writeToFile:[baseDir stringByAppendingPathComponent:fname]
atomically:YES];
//FOR LOCAL URL OF THE IMAGE
//NSString *imageURL = [baseDir stringByAppendingPathComponent:fname];
//UIImage *myImg =[UIImage imageWithContentsOfFile:imageURL];
//NSLog(#"%# URL OF IMAGE ",imageURL);
NSLog(#"Image %d has %d size",i,data.length);
_sizeOfSelectedImage +=data.length;
NSLog(#"%d is the size",_sizeOfSelectedImage);
dispatch_group_leave(group);
}
failureBlock:^(NSError *error){
dispatch_group_leave(group);
}];
}
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
// Do your call back on main thread here
NSLog(#"COPIED %lu FILE INTO LOCAL MEMORY AND TOTAL SIZE COPIED IS %d ",(unsigned long)assets.count,_sizeOfSelectedImage);
// Your code here
});
I have been faced this issue since more than a week, i am not able to get original photo/video path from assets-library url.
I can get its data by saving this file to my app SandBox, but here i want to avoid this things to again create another copy of that file.
I have investing this in DropBox, they are directly uploading from assets-library url. So, please help me to get out this issue.
Thanks in advance.
Here is my code:
-(NSString*) videoAssetURLToTempFile:(NSString*)combineURL{
self.activityIndicator.hidden = FALSE;
NSLog(#"combineURL: %#",combineURL);
NSArray *arr = [combineURL componentsSeparatedByString:#"->"];
NSString *index = [arr objectAtIndex:0];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#",[arr objectAtIndex:1]]];
//url like: "assets-library://asset/asset.MOV?id=78988A2B-203B-41B9-8EDA-F3029303DFBF&ext=MOV"
NSString * surl = [url absoluteString];
NSString * ext = [surl substringFromIndex:[surl rangeOfString:#"ext="].location + 4];
NSTimeInterval ti = [[NSDate date]timeIntervalSinceReferenceDate];
NSString *fname = [NSString stringWithFormat: #"%f.%#",ti,ext];
NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:#"SAVED_PHOTOS"];
// New Folder is your folder name
NSError *error = nil;
if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
[[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error];
NSString *tmpfile = [stringPath stringByAppendingPathComponent:fname];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
ALAssetRepresentation * rep = [myasset defaultRepresentation];
NSLog(#"video url: %#",rep.url);
NSUInteger size = [rep size];
NSLog(#"file size: %#",[NSString stringWithFormat:#"%llu",(unsigned long long)rep.size]);
if (!appDelegate.arrFileSize) {
appDelegate.arrFileSize = [[NSMutableArray alloc] init];
}
[appDelegate.arrFileSize replaceObjectAtIndex:[index integerValue] withObject:[NSString stringWithFormat:#"%llu",(unsigned long long)rep.size]];
[appDelegate.accessToken setObject:appDelegate.arrFileSize forKey:#"FileSize"];
[appDelegate.accessToken synchronize];
NSLog(#"video fileSize: %#",[self convertbyteToKB_MB:(unsigned long long)rep.size]);
unsigned long long freeSpaceSize = [self getFreeDiskspace];
NSLog(#"freeSpaceSize: %llu",freeSpaceSize);
if (freeSpaceSize<rep.size && rep.size<1073741824) {
NSString *alertMsg;
if (IS_IPHONE) {
alertMsg = [NSString stringWithFormat:#"App requires %# free storage space to upload this video. To proceed with this upload, please go to your iPhone's Settings and clear some space.",[self convertbyteToKB_MB:(unsigned long long)rep.size]];
}
else{
alertMsg = [NSString stringWithFormat:#"App requires %# free storage space to upload this video. To proceed with this upload, please go to your iPad's Settings and clear some space.",[self convertbyteToKB_MB:(unsigned long long)rep.size]];
}
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:alertMsg delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
dispatch_async(dispatch_get_main_queue(), ^{
self.waitToUploadLbl.hidden = TRUE;
});
});
}
else{
if (rep.size>=1073741824) {
dispatch_async(dispatch_get_main_queue(), ^{
self.waitToUploadLbl.hidden = TRUE;
});
}
else{
convertingTotal++;
dispatch_async(dispatch_get_main_queue(), ^{
self.waitToUploadLbl.hidden = FALSE;
});
const int bufferSize = 8*1024*1024;
FILE* f = fopen([tmpfile cStringUsingEncoding:1], "wb+");
if (f == NULL) {
return;
}
Byte * buffer = (Byte*)malloc(bufferSize);
unsigned long long read = 0, offset = 0, written = 0;
NSError* err;
if (size != 0) {
do {
read = (unsigned long long)[rep getBytes:buffer
fromOffset:offset
length:bufferSize
error:&err];
written = (unsigned long long)fwrite(buffer, sizeof(char), read, f);
offset += read;
} while (read != 0);
blockedNo++;
}
fclose(f);
NSLog(#"file saved to temp");
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"total: %d blockedNo: %d",convertingTotal,blockedNo);
self.waitToUploadLbl.hidden = TRUE;
});
}
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
//NSLog(#"Can not get asset - %#",[myerror localizedDescription]);
};
if(url)
{
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock:resultblock
failureBlock:failureblock];
}
self.activityIndicator.hidden = TRUE;
#try {
[appDelegate.uploadArray1 replaceObjectAtIndex:[index integerValue] withObject:tmpfile];
[appDelegate.accessToken setObject:appDelegate.uploadArray1 forKey:#"UploadArray"];
[appDelegate.accessToken synchronize];
NSLog(#"temporary path: %#",tmpfile);
[self performSelector:#selector(uploadphotoToServer:) withObject:index afterDelay:1];
}
#catch (NSException *exception) {
NSLog(#"Error: %#",exception);
}
#finally {
dispatch_async(dispatch_get_main_queue(), ^{
if (convertingTotal==blockedNo) {
self.waitToUploadLbl.hidden = TRUE;
}
});
}
return tmpfile;
}
i hope this will help you
NSString *str_url=[arrURL objectAtIndex:indexPath.row];//put your index
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
NSURL* aURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#",str_url]];
[assetLibrary assetForURL:aURL resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
cell.imageCell.image=[UIImage imageWithData:data];
} failureBlock:^(NSError *error)
{
NSLog(#"Error: %#",[error localizedDescription]);
}];
I have a urls like
"assets-library://asset/asset.PNG?id=2B9DB56C-B9C6-4F4E-AD51-8A5E5F1DD2AA&ext=PNG"
in "images" array. How i can get NSData from media, by this url?
I need use NSData in this code:
#pragma mark VK methods
+(NSMutableArray*)attachmentIds:(NSArray*)images forMe:(NSDictionary*)me{
NSMutableArray *attachmentsList = [NSMutableArray new];
for (int i = 0; i<images.count; i++){
NSData *imageData = [NSData dataWithContentsOfURL:[images objectAtIndex:i] ];
NSString *serverUrl = [self getServerForVKUploadPhotoToWall:me];
NSDictionary *uploadResult = [self sendVKPOSTRequest:serverUrl withImageData:imageData];
NSString *hash = [uploadResult objectForKey:#"hash"];
NSString *photo = [uploadResult objectForKey:#"photo"];
NSString *server = [uploadResult objectForKey:#"server"];
NSString *attach_id = [self getVKAttachIdforUser:me photo:photo server:server hash:hash];
[attachmentsList addObject:attach_id];
}
return attachmentsList;
}
But NSData *imageData = [NSData dataWithContentsOfURL:[images objectAtIndex:i]];
isn't working;
I solved my question. Thanks https://www.cocoacontrols.com/controls/doimagepickercontroller
- (NSData *)getCroppedData:(NSURL *)urlMedia
{
__block NSData *iData = nil;
__block BOOL bBusy = YES;
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = myasset.defaultRepresentation;
long long size = representation.size;
NSMutableData *rawData = [[NSMutableData alloc] initWithCapacity:size];
void *buffer = [rawData mutableBytes];
[representation getBytes:buffer fromOffset:0 length:size error:nil];
iData = [[NSData alloc] initWithBytes:buffer length:size];
bBusy = NO;
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(#"booya, cant get image - %#",[myerror localizedDescription]);
};
[_assetsLibrary assetForURL:urlMedia
resultBlock:resultblock
failureBlock:failureblock];
while (bBusy)
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
return iData;
}
I think you can look at this question. This will allow you to retrieve a UIImage from the given asset URL, which can then be converted into NSData.
The Asset URL is not a file URL, so the dataWithContentsOfURL fails.
I can get images from Photo Library through ALAssetsLibrary:
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
// Copy the photo image to the `/Documents` directory of this App here
}
};
void (^assetGroupEnumerator )(ALAssetsGroup*, BOOL*) = ^(ALAssetsGroup *group, BOOL *stop){
if (group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
// fetch
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock:^(NSError *error) {
NSLog(#"failed");
}];
I want to copy specific images to the local directory (App_home/Documents), but I don't know how to exactly do this job by handling ALAsset objects.
Try with following Code
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:YourURL resultBlock:^(ALAsset *asset)
{
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
[data writeToFile:photoFile atomically:YES];//you can save image later
}
failureBlock:^(NSError *err)
{
NSLog(#"Error: %#",[err localizedDescription]);
}
];
For get Image In document directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newPath = [documentsDirectory stringByAppendingPathComponent:#"Your_Image_Name"];
UIImage *myImg = [UIImage imageWithContentsOfFile:newPath]
It may be helpful to you . In this the outputFileURL is of type NSURL
NSData *videoData = [NSData dataWithContentsOfURL:outputFileURL];
[data writeToFile:destinationPath atomically:YES];//you can save image later
You can get photo raw binary with below implementation and save to your 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 must be aware, this raw data has not applied any filter iOS default gallery App added, if you want these filter applied, you should get these XMP liked filter from [ALAssetRepresentation metadata] and create filters with [CIFilter filterArrayFromSerializedXMP:inputImageExtent:error:], then apply them on full resolution image, finally save this processed image as JPEG or PNG to file.
Below 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;
//add filter to image
ALAssetRepresentation *representation = asset.defaultRepresentation;
adjustmentXMP = [representation.metadata objectForKey:#"AdjustmentXMP"];
adjustmentXMPData = [adjustmentXMP dataUsingEncoding:NSUTF8StringEncoding];
extend.size = representation.dimensions;
filters = [CIFilter filterArrayFromSerializedXMP:adjustmentXMPData inputImageExtent:extend error:&error];
if(filters)
{
CIImage *image = [CIImage imageWithCGImage:imageRef];
CIContext *context = [CIContext contextWithOptions:nil];
for (CIFilter *filter in filters)
{
[filter setValue:image forKey:kCIInputImageKey];
image = [filter outputImage];
}
imageRef = [context createCGImage:image fromRect:image.extent];
}
return imageRef;
}
hi I am using the AVCam Liberary for automatic image capturing.I dont want to
save the image in photo libriary I want to save the image in document directory .it saves the image but having problem when i
load this image gives access bad.
- (void) captureStillImage
{
AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([stillImageConnection isVideoOrientationSupported])
[stillImageConnection setVideoOrientation:orientation];
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
if (error) {
if ([[self delegate] respondsToSelector:#selector(captureManager:didFailWithError:)]) {
[[self delegate] captureManager:self didFailWithError:error];
}
}
};
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
UIImage *image = [[UIImage alloc] initWithData:imageData];
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/Image.jpg", docDirectory];
NSData *imageDataToSave = [NSData dataWithData:UIImagePNGRepresentation(image)];
[imageDataToSave writeToFile:filePath atomically:YES];
//[self saveImage:image];
completionBlock:completionBlock];
[image release];
[library release];
}
else
completionBlock(nil, error);
if ([[self delegate] respondsToSelector:#selector(captureManagerStillImageCaptured:)]) {
[[self delegate] captureManagerStillImageCaptured:self];
}
}];
}
and loading the image
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/Image.jpg", docDirectory];
UIImage* loadedImage = [UIImage imageWithContentsOfFile:filePath];
[ImageView setImage:loadedImage];
when this loadedImage is assign to any UIImage
While writing the file try -
[UIImagePNGRepresentation(self.imageView.image) writeToFile:pngPath atomically:YES];