{"id":2646,"date":"2011-08-22T10:56:51","date_gmt":"2011-08-22T05:56:51","guid":{"rendered":"http:\/\/aasims.wordpress.com\/?p=2646"},"modified":"2025-04-27T19:20:29","modified_gmt":"2025-04-27T19:20:29","slug":"getting-a-screencapture-of-uiview","status":"publish","type":"post","link":"https:\/\/aasimnaseem.com\/blog\/getting-a-screencapture-of-uiview\/","title":{"rendered":"Getting a Screen Capture of UIView"},"content":{"rendered":"<p>Some times you have to capture a portion of you iPhone application programmatically;<br \/>\nThe quickest way is to pass the target view to following method and get its screenshot as an UIImage;<\/p>\n<p>[sourcecode language=&#8221;objc&#8221;]<br \/>\n-(UIImage*)captureFullScreen:(UIView*) targetView{<br \/>\n    UIGraphicsBeginImageContext(targetView.view.frame.size);<br \/>\n    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];<br \/>\n    UIImage *fullScreenshot = UIGraphicsGetImageFromCurrentImageContext();<br \/>\n    UIGraphicsEndImageContext();<br \/>\n    UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil);<br \/>\n    return fullScreenshot;<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p><!--more--><\/p>\n<pre><\/pre>\n<p>&#8211; To capture the whole screen, you don&#8217;t need to pass any parameter to this method; instead, use<strong> <em>self.view.frame <\/em><\/strong>in the first line.<\/p>\n<p>&#8211; To save the captured image into your device&#8217;s album, use\u00a0 the following.<\/p>\n<p>[sourcecode language=&#8221;objc&#8221;]<\/p>\n<p> UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil);<\/p>\n<p>[\/sourcecode]<\/p>\n<p>HAPPY DEVELOPMENT;<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/s05.flagcounter.com\/count\/C1H\/bg=FFFFFF\/txt=000000\/border=FFFFFF\/columns=6\/maxflags=248\/viewers=0\/labels=1\/pageviews=1\/\" alt=\"free counters\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some times you have to capture a portion of you iPhone application programmatically; The quickest way is to pass the target view to following method and get its screenshot as an UIImage; [sourcecode language=&#8221;objc&#8221;] -(UIImage*)captureFullScreen:(UIView*) targetView{ UIGraphicsBeginImageContext(targetView.view.frame.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *fullScreenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil); return fullScreenshot;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":5005,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[253,405,406,1036,1037,1038,1039,1040],"class_list":["post-2646","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","tag-capture-screenshot","tag-getting-a-screencapture-of-any-uiview","tag-getting-a-screencapture-of-any-uiview-prorammatically","tag-uigraphicsbeginimagecontext","tag-uigraphicsendimagecontext","tag-uigraphicsgetcurrentcontext","tag-uigraphicsgetimagefromcurrentimagecontext","tag-uiimagewritetosavedphotosalbum"],"_links":{"self":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/comments?post=2646"}],"version-history":[{"count":5,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2646\/revisions"}],"predecessor-version":[{"id":5169,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2646\/revisions\/5169"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media\/5005"}],"wp:attachment":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media?parent=2646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/categories?post=2646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/tags?post=2646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}