views:

328

answers:

3

Hi I am working on an app where I need to save a part of iphone's screen shot as JPEG and then send this through email. The part of screen has some text labels, fields etc. Any ideas please on how can I save part of screen as JPEG (I am a newbie therefore any help/sample code is highly appreciated)

A: 

From http://blogs.zdnet.com/mobile-gadgeteer/?p=1278:

When you are on a screen that you want to capture, press and hold the Home button and then press the the power/sleep button. Your screen shot will then appear photo gallery on your iPhone where you can send it or sync it as needed.

Justin Ethier
The question is looking to do this in code.
MystikSpiral
Exactly, I was looking for a coding solution to this. Nevertheless, thanks for reply.
Ali
A: 

You will need a QuartzCore library.

See this one: http://www.iphonedevsdk.com/forum/iphone-sdk-development/2353-possible-make-screenshot-programmatically-2.html

Bird
+3  A: 

The following code will save the contents of a view to the user's photo library. You should be able to modify it to be able to email the file instead.

  CGRect myRect = [myView bounds];
  UIGraphicsBeginImageContext(myRect.size);

  CGContextRef ctx = UIGraphicsGetCurrentContext();
  [[UIColor blackColor] set];
  CGContextFillRect(ctx, myRect);

  [myView.layer renderInContext:ctx];

  UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();

  // Replace the following line with code that emails the image
  UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
  UIGraphicsEndImageContext();
Frank Schmitt