some_id
some_id

Reputation: 29886

Taking a screenshot of a view

How does one take a screenshot of a view with code?

I have read on some forums and there was a post made by an apple engineer and the code didnt work.

Is there a built in way to do this or what is the correct way to screenshot a view?

Upvotes: 0

Views: 1151

Answers (2)

Black Frog
Black Frog

Reputation: 11703

Apple just updated Technical Q&A QA1703 Screen Capture in UIKit Applications. I just put this in my code and it works well.

Upvotes: 7

JustSid
JustSid

Reputation: 25318

You can let the layer of the view render into a CGContextRef. This would be something like this:

[[myView layer] renderInContext:someContext];

You can then get the UIImage representation of the context and save it or so. However, please remark that this is kind of slow as the whole layer plus it sublayers have to be rendered again into the new context.

Don't forget to include and link against QuartCore for this.

Upvotes: 1

Related Questions