0

I must be doing something wrong, but I could use some advice on the following:

I am trying to capture a partial screen on both iPad and iPad retina.

I can get the portrait views ok, but I cannot get the right side of a landscape view to be in bounds.

This is the code I'm using (I did not have this problem before UIGetScreenImage() was made contraband)..

CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext(); 
[[UIColor blackColor] set]; 
CGContextFillRect(ctx, screenRect);
[self.view.layer renderInContext:ctx];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake (0, 100, self.view.bounds.size.width, (self.view.bounds.size.height - 200)));


UIImage *img2Save = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// Request to save the image to camera roll
UIImageWriteToSavedPhotosAlbum(img2Save, self, nil, nil);

These are the two images I get for portrait, and landscape:

Portrait

Landscape

ICL1901
  • 7,632
  • 14
  • 90
  • 138

1 Answers1

1

If you are using your window as your frame, it will always show up in portrait mode. You can set screenRect to a full-screen view, which should work in both portrait and landscape mode.

Alec Sanger
  • 4,442
  • 1
  • 33
  • 53
  • Thank you. I'm googling and binging.. Do you have a preferred method to set this. The best I can find is to check orientation, and set coordinates manually. David – ICL1901 May 17 '12 at 05:31
  • I found this SO post - http://stackoverflow.com/questions/5677716/how-to-get-the-screen-width-and-height-in-ios that gives me a better convenience method. But you put me in the right direction, and i greatly appreciate that. So I'm marking this closed.. Thank you again. – ICL1901 May 17 '12 at 05:50