views:

39

answers:

2

CGImageRef screen = UIGetScreenImage(); UIImage* image = [UIImage imageWithCGImage:screen]; CGImageRelease(screen);

// You could, e.g., save the captured image to photo album UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

  • (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { UIAlertView *alert;

    // Unable to save the image
    if (error) alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unable to save image to Photo Album." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; else // All is well alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Image saved to Photo Album." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; [alert release]; }

im using this coading and its not working on simulator but its works on device and saving that image in photos. is there any way to work it for simulator? or is there any way that i can store that captured image in to document or resource folder?

thanks in advance.

+1  A: 

First of all, UIGetScreenImage() is not supported on the simulator, as far as I know.

Second, if you intend to release this app, stop using UIGetScreenImage(), because it's been prohibited by Apple again, as you can see at: https://devforums.apple.com/message/149553#149553.

Third, if you are using it to capture data from the camera, you will have to the new AVFoundation (Yes, I know that the necessary methods are not available on iOS3).

Fourth, if you need to grab the info on the UIKit elements on your screen: http://developer.apple.com/iphone/library/qa/qa2010/qa1703.html

vfn
A: 

ok i put this code and getting image, but im not getting any label with it .. any hint about it?

//im1 = first image //im2 =second image

UIGraphicsBeginImageContext(im1.frame.size); [im1.image drawInRect:CGRectMake(0.0, 0.0, im2.frame.size.width, im2.frame.size.height)]; [im2.image drawInRect:CGRectMake(0.0, 0.0, im2.frame.size.width, im2.frame.size.height)]; //blendMode:kCGBlendModeNormal alpha:1.0];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

i tried to add label l3 like this in between those images but it wasnot working. [l3.text drawinRect:CGRectMake(0.0, 0.0, im2.frame.size.width, im2.frame.size.height) withFont: nil];

Syed Faraz Haider Zaidi