iPhone Choking on Certain Image Formats - iphone

My app allows upload of an image from the camera roll. Some images are causing the app to crash when I attempt to save them to my documents directory prior to upload. I'm converting the image to a PNG prior to saving, but that hasn't helped. Here's the error...
Tue Aug 31 20:39:13 localhost XXX[76409] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 1600 bytes/row.
Tue Aug 31 20:39:13 localhost XXX[76409] <Error>: CGContextConcatCTM: invalid context 0x0
Tue Aug 31 20:39:13 localhost XXX[76409] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
Tue Aug 31 20:39:13 localhost XXX[76409] <Error>: CGContextDrawImage: invalid context 0x0
Tue Aug 31 20:39:13 localhost XXX[76409] <Error>: CGBitmapContextCreateImage: invalid context 0x0
and here's a sample of my code...
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSData *pngData = UIImagePNGRepresentation(img);
UIImage *pngImg = [UIImage imageWithData:pngData];
... code to save image ...
}

Note also that what you are doing is redundant and a waste of memory. img and pngImg are the same. Or is there a specific reason that you convert an image to png and then back to an image?

Related

App crash in didFinishPickingMediaWithInfo

My app is crashing when the user records a video and then clicks choose. Here is my code:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
//picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
picker.allowsEditing = NO;
picker.delegate = self;
picker.videoQuality = UIImagePickerControllerQualityTypeMedium;
[self presentModalViewController:picker animated:YES];
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// [self dismissModalViewControllerAnimated:YES];
AppDelegate *del = [[UIApplication sharedApplication]delegate];
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
moviePath = [[info objectForKey:UIImagePickerControllerMediaURL]path];..//using this for upload
del.globalMoviePath = moviePath;
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)== kCFCompareEqualTo)
{
moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
del.globalMoviePath = moviePath;
picker.videoMaximumDuration = 60.0f;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
NSLog(#"nrgkrg===>%#",moviePath);
videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"Urlllll===>%#",videoUrl);
videoData = [NSData dataWithContentsOfURL:videoUrl];
del.globalMoviePath = moviePath;
NSLog(#"video is====>%#",del.globalMoviePath);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[player stop];
videoImage = [[UIImageView alloc]initWithImage:thumbnail];
//NSLog(#"imegsvideo====>%#",thumbnail);
//if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath))
//{
// UISaveVideoAtPathToSavedPhotosAlbum (moviePath, self, #selector(video:didFinishSavingWithError:contextInfo:), nil);
// }
//MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
//UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
}
[self dismissModalViewControllerAnimated:YES];
//[[picker parentViewController] dismissModalViewControllerAnimated: YES];
}
When the user records a video and clicks choose app gets crashed but works fine when selected from camera roll.
Please help!!
Here's the log:
Nov 29 20:28:14 ReportCrash[259] <Notice>: Formulating crash report for process [254]
Nov 29 20:28:14 com.apple.launchd[1] <Warning>: (UIKitApplication:[0xcc37]) Job appears to have crashed: Segmentation fault: 11
Nov 29 20:28:14 backboardd[52] <Warning>: Application 'UIKitApplication:[0xcc37]' exited abnormally with signal 11: Segmentation fault: 11
Nov 29 20:28:14 ReportCrash[259] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Nov 29 20:28:14 ReportCrash[259] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/ using uid: 0 gid: 0, synthetic_euid: 501 egid: 0
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: Checking on job state for Photo Stream
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: No jobs scheduled for Photo Stream.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: Checking on job state for Shared Stream
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: No jobs scheduled for Shared Stream.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) PS: Media stream daemon stopping.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shared Streams daemon shutting down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shutting down state machine for personID 1446684163.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASStateMachine: 0x1ed3e060>: Shutting down uploader.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASStateMachine: 0x1ed3e060>: Shutting down downloader.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASStateMachine: 0x1ed3e060>: Shutting down state machine.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shutting down model.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSASServerSideModel: 0x1ed39d50>: Command Queue has shut down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Model has shut down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x1ee72590>: Shared Streams daemon has shut down.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Note ) mstreamd: <MSPowerBudget: 0x1ed394b0>: Stopping post-foreground timer.
Nov 29 20:28:38 mstreamd[257] <Notice>: (Warn ) mstreamd: mstreamd shutting down.
Nov 29 20:49:16 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:49:16 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 0
Nov 29 20:49:16 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType Detached
Nov 29 20:49:16 kernel[0] <Debug>: virtual IOReturn AppleUSBDeviceMux::message(UInt32, IOService *, void *) - kMessageInterfaceWasDeActivated
Nov 29 20:49:16 kernel[0] <Debug>: AppleUSBDeviceMux::reportStats: USB mux statistics:
Nov 29 20:49:16 kernel[0] <Debug>: USB mux: 190 reads / 0 errors, 899 writes / 0 errors
Nov 29 20:49:16 kernel[0] <Debug>: USB mux: 0 short packets, 0 dups
Nov 29 20:49:16 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_charging even though we are not in it, doing nothing
Nov 29 20:49:16 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:49:16 ptpd[104] <Notice>: PTP interface has been deactivated.
Nov 29 20:49:18 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_asleep even though we are not in it, doing nothing
Nov 29 20:49:18 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 1
Nov 29 20:49:18 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType USBHost
Nov 29 20:49:18 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:49:18 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:49:19 ptpd[104] <Notice>: PTP interface has been activated at high speed.
Nov 29 20:49:56 lockdownd[29] <Notice>: 2fe93000 special_case_get: MGCopyAnswer(kMGQMobileEquipmentIdentifier) returned NULL
Nov 29 20:49:56 lockdownd[29] <Notice>: 2fe93000 copy_phonenumber: CTSettingCopyMyPhoneNumber() returned NULL
Nov 29 20:49:56 mobile_installation_proxy[265] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: MobileInstallationBrowse was called without specifying an options dictionary containing kLookupReturnAttributesKey. This usage is inefficient and may cause performance problems. Break on MobileInstallationSlowLookupBreak to debug.
Nov 29 20:49:56 mobile_installation_proxy[265] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: Existing options dictionary: <CFBasicHash 0x1c545b90 [0x3bfb1100]>{type = mutable dict, count = 1,
entries =>
6 : <CFString 0x1c545bc0 [0x3bfb1100]>{contents = "ApplicationType"} = <CFString 0x1c545b30 [0x3bfb1100]>{contents = "User"}
}
Nov 29 20:49:57 mc_mobile_tunnel[267] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:49:57 mc_mobile_tunnel[267] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:49:57 mc_mobile_tunnel[268] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:49:57 mc_mobile_tunnel[268] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:49:57 lockdownd[29] <Notice>: 2fe93000 set_response_error: handle_start_session SessionActive
Nov 29 20:49:57 lockdownd[29] <Notice>: 2fe93000 set_response_error: handle_start_session SessionActive
Nov 29 20:50:03 mc_mobile_tunnel[270] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:50:03 mc_mobile_tunnel[270] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:51:31 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:51:31 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 0
Nov 29 20:51:31 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType Detached
Nov 29 20:51:31 kernel[0] <Debug>: virtual IOReturn AppleUSBDeviceMux::message(UInt32, IOService *, void *) - kMessageInterfaceWasDeActivated
Nov 29 20:51:31 kernel[0] <Debug>: AppleUSBDeviceMux::reportStats: USB mux statistics:
Nov 29 20:51:31 kernel[0] <Debug>: USB mux: 195 reads / 0 errors, 493 writes / 0 errors
Nov 29 20:51:31 kernel[0] <Debug>: USB mux: 0 short packets, 0 dups
Nov 29 20:51:31 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_charging even though we are not in it, doing nothing
Nov 29 20:51:31 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:51:31 ptpd[104] <Notice>: PTP interface has been deactivated.
Nov 29 20:51:41 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_asleep even though we are not in it, doing nothing
Nov 29 20:51:41 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableDetect 1
Nov 29 20:51:41 kernel[0] <Debug>: AppleD1881PMUPowerSource: AppleUSBCableType USBHost
Nov 29 20:51:41 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state unplugged_screen_off even though we are not in it, doing nothing
Nov 29 20:51:41 UserEventAgent[13] <Warning>: PLAggregateState Error: Leaving state pluggedin_screen_off even though we are not in it, doing nothing
Nov 29 20:51:41 ptpd[272] <Error>: ptpd: startResponder
Nov 29 20:51:41 kernel[0] <Debug>: launchd[272] Builtin profile: ptpd (sandbox)
Nov 29 20:51:42 ptpd[272] <Notice>: PTP interface has been activated at high speed.
Nov 29 20:51:43 lockdownd[29] <Notice>: 2ffcf000 verify_pair_record: The strings don't match. Is this really a UUID?
Nov 29 20:51:43 lockdownd[29] <Notice>: 2ffcf000 store_escrow_record: Creating escrow bag (hash=9263ecf9c114f3a5cecdf7a52df193b4ce25044f) for 30264900-17792825678462560
Nov 29 20:51:52 lockdownd[29] <Notice>: 01442000 verify_pair_record: The strings don't match. Is this really a UUID?
Nov 29 20:51:52 lockdownd[29] <Notice>: 01442000 store_escrow_record: Creating escrow bag (hash=9de39584e1758f58137d28e4bd8c2fd79b5ba0a2) for 30264900-1682617038156454252
Nov 29 20:51:53 lockdownd[29] <Notice>: 01442000 special_case_get: MGCopyAnswer(kMGQMobileEquipmentIdentifier) returned NULL
Nov 29 20:51:53 lockdownd[29] <Notice>: 01442000 copy_phonenumber: CTSettingCopyMyPhoneNumber() returned NULL
Nov 29 20:51:53 mobile_installation_proxy[275] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: MobileInstallationBrowse was called without specifying an options dictionary containing kLookupReturnAttributesKey. This usage is inefficient and may cause performance problems. Break on MobileInstallationSlowLookupBreak to debug.
Nov 29 20:51:53 mobile_installation_proxy[275] <Error>: 0x3cbd7b88 MobileInstallationSlowLookupBreak: Existing options dictionary: <CFBasicHash 0x1c5119d0 [0x3bfb1100]>{type = mutable dict, count = 1,
entries =>
6 : <CFString 0x1c511a00 [0x3bfb1100]>{contents = "ApplicationType"} = <CFString 0x1c511970 [0x3bfb1100]>{contents = "User"}
}
Nov 29 20:51:53 mc_mobile_tunnel[277] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:51:53 mc_mobile_tunnel[277] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:51:53 mc_mobile_tunnel[278] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:51:53 mc_mobile_tunnel[278] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:51:55 mc_mobile_tunnel[280] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:51:55 mc_mobile_tunnel[280] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
Nov 29 20:52:01 iPhone4S mc_mobile_tunnel[282] <Notice>: (Note ) MC: mc_mobile_tunnel starting.
Nov 29 20:52:01 iPhone4S mc_mobile_tunnel[282] <Notice>: (Note ) MC: mc_mobile_tunnel shutting down.
this is because may be you are dismissing view just after dismissing picker:
[picker dismissModalViewControllerAnimated:YES];
[self dismissModalViewControllerAnimated:YES];
as you have used animated YES, the picker is not yet dismissed so either use new API
[picker dismissViewControllerAnimated:YES completion:^{
[self dismissModalViewControllerAnimated:YES];
}];
The App is crashes because in iOS6 [self dismissModalViewControllerAnimated:YES];
is deprecated you replace it with [picker dismissViewControllerAnimated:YES completion:nil]; may solve you issue.

iPhone app crashes randomly on device while connecting to remote server?

i have an app which post and get data using webservice it's working fine but while testing the app rigorously crashes with message Application Exited abnormally with signal 9(Killed) .
Mon Jul 16 21:07:55 unknown MyApp[167] <Warning>: NVVC Dealloc
Mon Jul 16 21:08:23 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.company.MyApp[0xe271]) Bug: launchd_core_logic.c:2688 (24132):10
Mon Jul 16 21:08:23 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.company.MyApp[0xe271]) Working around 5020256. Assuming the job crashed.
Mon Jul 16 21:08:23 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.company.MyApp[0xe271]) Job appears to have crashed: Segmentation
fault
Mon Jul 16 21:08:23 unknown SpringBoard[29] <Warning>: Application 'MyApp' exited abnormally with signal 11: Segmentation fault
Mon Jul 16 21:09:04 unknown lockdownd[20] <Error>: (0x403000) handle_connection: Could not receive USB message #7 from Xcode. Killing connection
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.mobilemail[0x55fb]) Exited: Killed
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.mobilephone[0xa13c]) Exited: Killed
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.MyApp.app[0x137]) Exited: Killed
Mon Jul 16 22:00:39 unknown com.apple.launchd[1] <Notice>: (com.apple.accessoryd) Exited: Killed
Mon Jul 16 22:00:41 unknown SpringBoard[29] <Warning>: Application 'Mail' exited abnormally with signal 9: Killed
Mon Jul 16 22:00:41 unknown SpringBoard[29] <Warning>: Memory level is not normal (15%). Delaying auto-relaunch of 'Mail' for 30 seconds. Mon Jul 16 22:00:41 unknown SpringBoard[29] <Warning>: Application 'app' exited abnormally with signal 9: Killed
Mon Jul 16 22:00:42 unknown SpringBoard[29] <Warning>: Application 'Phone' exited abnormally with signal 9: Killed
i googled around but i could not found any solution or reason for killing app.please Help me to resolve the issue.
Edit#2
Here i am adding some code where i am getting crash in my application.
#try {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSUserDefaults *defaults2 = [NSUserDefaults standardUserDefaults];
NSString *string = [NSString stringWithFormat:URL];
NSURL *url = [NSURL URLWithString:string];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
// NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:synStr]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
[connection release];
if(label != nil){
progressView = [[ProgressView showHUDAddedTo:self.tabBarController.view animated:YES]retain];
progressView.labelText = label;
}
[request release];
}
#catch (NSException * e) {
}
You're using NSURLConnection incorrectly. If you look here you can see that you are starting an asynchronous connection. It looks like you are releasing the connection object before it has finished, which is causing the segmentation fault.

merge two images into one image in iPhone

I need to merge two images into one image, here is my code:
-(UIImage*)mergeImage:(UIImage*)mask overImage:(UIImage*)source inSize:(CGSize)size
{
//Capture image context ref
UIImageView *totalimage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
UIImageView *firstImage=[[UIImageView alloc] initWithImage:mask];
UIImageView *secondImage=[[UIImageView alloc] initWithImage:source];
[totalimage addSubview:firstImage];
[totalimage addSubview:secondImage];
UIGraphicsBeginImageContext(totalimage.bounds.size);
[totalimage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Draw images onto the context
[source drawInRect:CGRectMake(0, 0, source.size.width, source.size.height)];
[mask drawInRect:CGRectMake(0, 0, mask.size.width, mask.size.height)];
return viewImage;
}
I call this method as follows:
UIImage *totalImage = [self mergeImage:self.Apicimage overImage:questionImage inSize:CGSizeMake(100, 100)];
but on execution I get this output:
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSaveGState: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetBlendMode: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetAlpha: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextTranslateCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextScaleCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextConcatCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextDrawImage: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextRestoreGState: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSaveGState: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetBlendMode: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextSetAlpha: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextTranslateCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextScaleCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextConcatCTM: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextDrawImage: invalid context 0x0
Jun 15 16:11:06 iPad-2 VueGuides[9195] <Error>: CGContextRestoreGState: invalid context 0x0
can anyone guide me please. How can I merge two images?
your code
[source drawInRect:CGRectMake(0, 0, source.size.width, source.size.height)];
[mask drawInRect:CGRectMake(0, 0, mask.size.width, mask.size.height)];
should be written before
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Random img saving error on some iPhone 4s and iPod Touches

i encountered a weird error. i will like the app to save an image into camera roll.
but a small amount of device are giving me error saving msg.
EDIT: ERROR Log
"Failed to encode image for saved photos." UserInfo=0x3e7170 {NSUnderlyingError=0x389310 "Failed to encode image for saved photos.", NSLocalizedDescription=Failed to encode image for saved photos.
May 22 14:13:34 unknown assetsd[281] <Error>: ImageIO: CGImageDestinationAddImage image parameter is nil
May 22 14:13:34 unknown assetsd[281] <Error>: ImageIO: CGImageDestinationFinalize image destination does not have enough images
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetBaseCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSaveGState: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextFillRects: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextSetBaseCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextSaveGState: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextFillRects: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextConcatCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextDrawImage: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextConcatCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextDrawImage: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextRestoreGState: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGBitmapContextCreateImage: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGContextRestoreGState: invalid context 0x0
May 22 14:13:34 unknown com.apple.assetsd[281] <Notice>: May 22 14:13:34 SLQ-iTouch assetsd[281] <Error>: CGBitmapContextCreateImage: invalid context 0x0
>
below are my code used to save the images.
- (IBAction)saveImage:(id)sender {
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.dimBackground = YES;
HUD.labelText = #"Its saving!";
self.imageOverlay.alpha = 1;
self.savedImage = [self maskImage:self.imgView withMask:self.baseImgView];
UIImageWriteToSavedPhotosAlbum(self.savedImage, self, #selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
NSString *message;
NSString *title;
if (!error) {
title = NSLocalizedString(#"Save Success", #"");
message = NSLocalizedString(#"Save Success Message", #"");
HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Checkmark.png"]];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = #"We’re saved - WooHoo!!";
[HUD hide:YES afterDelay:1.5];
saved =1;
self.imageOverlay.alpha =0.85;
[self performSelector:#selector(saveSuccess) withObject:nil afterDelay:1.5];
} else
{
title = NSLocalizedString(#"Save Failed", #"");
message = [error description];
HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sad_face.png"]];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = #"Error! Try saving photo again :p";
[HUD hide:YES afterDelay:3];
}
}
- (UIImage*) maskImage:(UIImageView *)maskImage withMask:(UIImageView *)cropImage
{
UIImage *image = nil;
UIImage *imagePNG = nil;
CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0); //retina res
[self.viewForImg.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imgData = UIImagePNGRepresentation ( image ); // get PNG representation
imagePNG = [UIImage imageWithData:imgData]; // wrap UIImage around PNG representation
return imagePNG;
}
- (UIImage*) maskImage:(UIImageView *)maskImage withMask:(UIImageView *)cropImage
{
UIImage *image = nil;
UIImage *imagePNG = nil;
CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0); //retina res
[self.viewForImg.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
NSData *imgData = UIImagePNGRepresentation ( image ); // get PNG representation
imagePNG = [UIImage imageWithData:imgData]; // wrap UIImage around PNG representation
UIGraphicsEndImageContext();
return imagePNG;
}

Application Crashed - Wired Crash

What does this error mean?
Nov 8 17:57:10 unknown configd[25] <Notice>: jetsam: kernel memory event (91), free: 670, active: 2840, inactive: 2253, purgeable: 0, wired: 15143
Nov 8 17:57:11 unknown SpringBoard[92] <Warning>: Received memory warning. Level=2
Nov 8 17:57:11 unknown MobileMail[6432] <Warning>: Received memory warning. Level=2
Nov 8 17:57:11 unknown configd[25] <Notice>: jetsam: kernel termination snapshot being created
Nov 8 17:57:11 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.mobileipod[0xe0a1]) Exited: Killed: 9
Nov 8 17:57:11 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.mobilemail[0xbebe]) Exited: Killed: 9
Nov 8 17:57:11 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:paradigm.PaymentSystemiPad[0x6c80]) Bug: launchd_core_logic.c:3795 (24506):0
Nov 8 17:57:11 unknown DTMobileIS[6377] <Warning>: _memoryNotification : <NSThread: 0x1c5361d0>{name = (null), num = 1}
Nov 8 17:57:11 unknown com.apple.debugserver-50[6480] <Warning>: 1 [1950/1503]: error: ::read ( 4, 0x2ff669f0, 1024 ) => -1 err = Bad file descriptor (0x00000009)
Nov 8 17:57:11 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:paradigm.PaymentSystemiPad[0x6c80]) Bug: launchd_core_logic.c:3794 (24506):3
Nov 8 17:57:11 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:paradigm.PaymentSystemiPad[0x6c80]) Bug: launchd_core_logic.c:3202 (24506):10
Nov 8 17:57:11 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:paradigm.PaymentSystemiPad[0x6c80]) Working around 5020256. Assuming the job crashed.
Nov 8 17:57:11 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:paradigm.PaymentSystemiPad[0x6c80]) Job appears to have crashed: Segmentation fault: 11
Nov 8 17:57:11 unknown SpringBoard[92] <Warning>: Application 'Mail' exited abnormally with signal 9: Killed: 9
Nov 8 17:57:12 unknown DTMobileIS[6377] <Warning>: _memoryNotification : {
OSMemoryNotificationLevel = 0;
timestamp = "2011-11-08 12:27:11 +0000";
}
Nov 8 17:57:12 unknown DTMobileIS[6377] <Warning>: _memoryNotification : <NSThread: 0x1c5361d0>{name = (null), num = 1}
Nov 8 17:57:12 unknown DTMobileIS[6377] <Warning>: _memoryNotification : {
OSMemoryNotificationLevel = 0;
timestamp = "2011-11-08 12:27:12 +0000";
}
Nov 8 17:57:12 unknown SpringBoard[92] <Warning>: Application 'PaymentSystemiPad' exited abnormally with signal 11: Segmentation fault: 11
Nov 8 17:57:12 unknown SpringBoard[92] <Warning>: Application 'iPod' exited abnormally with signal 9: Killed: 9
Nov 8 17:57:12 unknown kernel[0] <Debug>: launchd[6486] Builtin profile: MobileMail (sandbox)
Nov 8 17:57:13 unknown ReportCrash[6485] <Error>: libMobileGestalt loadBasebandMobileEquipmentInfo: CommCenter error: 1:45
Nov 8 17:57:13 unknown ReportCrash[6485] <Error>: libMobileGestalt copyInternationalMobileEquipmentIdentity: Could not get mobile equipment info dictionary
Nov 8 17:57:13 unknown ReportCrash[6485] <Error>: Saved crashreport to /Library/Logs/CrashReporter/LowMemory-2011-11-08-175713.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
Nov 8 17:59:12 unknown SpringBoard[92] <Notice>: MultitouchHID(1f55bf50) uilock state: 0 -> 1
This mean that you have allocated a lot of memory and Received memory warning. I assume you have memory leaks or load many images/resources into memory. Try to research your code and find places where you load resources.