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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
I found this SO post - stackoverflow.com/questions/5677716/… 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.