views:

51

answers:

2

On click event of a button

[mybutton addTarget:self action:@selector(captureView)
     forControlEvents:UIControlEventTouchUpInside];


- (void)captureView {
    UIGraphicsBeginImageContext(CGSizeMake(320,480));
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];
    UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSLog(@"%@",screenShot);

}

My screenshot prints UIImage: 0x4b249c0. Is this correct code to take a screen short of a particular area of an iphone app? Where this image store at that particular time. How can i see those images?

A: 

The UIImage is just an in-memory representation of the screenshot you've taken. You will need to write it out somewhere if you want to save it. For example, the following code will write that image to the user's photo library:

UIImageWriteToSavedPhotosAlbum(screenShot, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

Remember to retain the image and release it within your -image:didFinishSavingWithError:contextInfo: callback method.

You can also manually save out an image as a PNG or JPEG using code like the following:

NSData *imageData = UIImagePNGRepresentation(screenShot);
[imageData writeToFile:pathToSaveImage atomically:YES];
Brad Larson
A: 

Here your image is in the memory itself and you need to save it somewhere say in Bundle .

mrugen