<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codec &#187; pixel</title>
	<atom:link href="http://www.trembl.org/codec/tag/pixel/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.trembl.org/codec</link>
	<description>A Personal Polylogic Code/Decode &#039;Zettelkasten&#039;</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:38:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Programmatically capture UIView</title>
		<link>http://www.trembl.org/codec/355/</link>
		<comments>http://www.trembl.org/codec/355/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 07:59:08 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[pixel]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[UIView]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/?p=355</guid>
		<description><![CDATA[Ok, a bit late to the party. Apple officially approved the use of UIGetScreenImage(). After carefully considering the issue, Apple is now allowing applications to use the function UIGetScreenImage() to programmatically capture the current screen contents. The function prototype is as follows: CGImageRef UIGetScreenImage&#40;void&#41;; https://devforums.apple.com/message/149553 How to caputure a view, ideally the live input of [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, a bit late to the party. Apple officially approved the use of UIGetScreenImage().</p>
<blockquote><p>After carefully considering the issue, Apple is now allowing applications to use the function UIGetScreenImage() to programmatically capture the current screen contents.  The function prototype is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGImageRef UIGetScreenImage<span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

</blockquote>
<p><a href="https://devforums.apple.com/message/149553">https://devforums.apple.com/message/149553</a></p>
<p><del datetime="2010-01-22T08:19:38+00:00">How to caputure a view, ideally the live input of the camera? Unfortunaly there&#8217;s no clean and clear interface for that. Only the undocumented UIGetScreenCapture() call:</del></p>
<p><a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/11219-screenshots-we-allowed-use-uigetscreenimage.html">http://www.iphonedevsdk.com/forum/iphone-sdk-development/11219-screenshots-we-allowed-use-uigetscreenimage.html</a></p>
<p><a href="http://stackoverflow.com/questions/1531815/takepicture-vs-uigetscreenimage">http://stackoverflow.com/questions/1531815/takepicture-vs-uigetscreenimage</a></p>
<p><a href="http://svn.saurik.com/repos/menes/trunk/iphonevnc/iPhoneVNC.mm">http://svn.saurik.com/repos/menes/trunk/iphonevnc/iPhoneVNC.mm<br />
</a></p>
<p><a href="http://blogs.oreilly.com/iphone/2008/10/creating-a-full-screen-camera.html<br />
">http://blogs.oreilly.com/iphone/2008/10/creating-a-full-screen-camera.html<br />
</a></p>
<p>But since UIGetScreenCapture() is an undocumented call (in 3.1), here are official ways to get the content of a view.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p><a href="http://icodeblog.com/2009/07/27/1188/">http://icodeblog.com/2009/07/27/1188/</a></p>
<p><a href="http://www.elrepositorio.com/?p=31">http://www.elrepositorio.com/?p=31</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/355/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UIImage → pixelData → UIImage Rountrip</title>
		<link>http://www.trembl.org/codec/347/</link>
		<comments>http://www.trembl.org/codec/347/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 06:17:30 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[CGImageRef]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[NSData]]></category>
		<category><![CDATA[pixel]]></category>
		<category><![CDATA[pixel value]]></category>
		<category><![CDATA[Quartz]]></category>
		<category><![CDATA[UIImage]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/?p=347</guid>
		<description><![CDATA[The questions is rather simple: How to manipulate single pixels of an UIImage? The answer is rather long; but includes a joyful trip into Quartz 2D Graphic land&#8230; // load image, convert to CGImageRef UIImage *c = &#91;UIImage imageNamed:@&#34;c.png&#34;&#93;; CGImageRef cRef = CGImageRetain&#40;c.CGImage&#41;; &#160; // png alpha to mask NSData* pixelData = &#40;NSData*&#41; CGDataProviderCopyData&#40;CGImageGetDataProvider&#40;cRef&#41;&#41;; // [...]]]></description>
			<content:encoded><![CDATA[<p>The questions is rather simple: How to manipulate single pixels of an UIImage?<br />
The answer is rather long; but includes a joyful trip into Quartz 2D Graphic land&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// load image, convert to CGImageRef</span>
UIImage <span style="color: #002200;">*</span>c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;c.png&quot;</span><span style="color: #002200;">&#93;</span>;
CGImageRef cRef <span style="color: #002200;">=</span> CGImageRetain<span style="color: #002200;">&#40;</span>c.CGImage<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// png alpha to mask</span>
<span style="color: #400080;">NSData</span><span style="color: #002200;">*</span> pixelData <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSData</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> CGDataProviderCopyData<span style="color: #002200;">&#40;</span>CGImageGetDataProvider<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #11740a; font-style: italic;">// image raw data</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//NSData* pixelDataRep = UIImagePNGRepresentation(c);</span>
<span style="color: #11740a; font-style: italic;">// compressed png data</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;pixelData %i&quot;, [pixelData length]);</span>
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;pixelDataRep %i&quot;, [pixelDataRep length]);</span>
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;pixelDataRep equal to pixelData: %@&quot;, [pixelData isEqualToData:pixelDataRep] ? @&quot;YES&quot; : @&quot;NO&quot;);</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//UIImage* newImage = [UIImage imageWithData:pixelData];</span>
<span style="color: #11740a; font-style: italic;">//[newImage drawInRect:CGRectMake(10, 340, 65, 65)];</span>
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;pixelData %@&quot;, pixelData);</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">unsigned</span> <span style="color: #a61390;">char</span><span style="color: #002200;">*</span> pixelBytes <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">unsigned</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>pixelData bytes<span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// return pointer to data</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// step through char data</span>
<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #002200;">&#91;</span>pixelData length<span style="color: #002200;">&#93;</span>; i <span style="color: #002200;">+=</span> <span style="color: #2400d9;">4</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// change accordingly</span>
	pixelBytes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> pixelBytes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span>;
	pixelBytes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">+</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> pixelBytes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">+</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
	pixelBytes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">+</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> pixelBytes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">+</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;
	pixelBytes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">+</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> <span style="color: #2400d9;">255</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #11740a; font-style: italic;">//1ms in Simulator , 5ms on iPhone 3GS , 65x65 pixel</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// copy bytes in new NSData</span>
<span style="color: #400080;">NSData</span><span style="color: #002200;">*</span> newPixelData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> dataWithBytes<span style="color: #002200;">:</span>pixelBytes length<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>pixelData length<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;newPixelData %@&quot;, newPixelData);</span>
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;newPixelData: %@&quot;, newPixelData ? @&quot;ok&quot; : @&quot;nil&quot;);</span>
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;newPixelData equal to pixelData: %@&quot;, [pixelData isEqualToData:newPixelData] ? @&quot;YES&quot; : @&quot;NO&quot;);</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// cast NSData as CFDataRef</span>
CFDataRef imgData <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>CFDataRef<span style="color: #002200;">&#41;</span>pixelData;
&nbsp;
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;CFDataGetLength %i&quot;, CFDataGetLength(imgData) );</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Make a data provider from CFData</span>
	CGDataProviderRef imgDataProvider <span style="color: #002200;">=</span> CGDataProviderCreateWithCFData<span style="color: #002200;">&#40;</span>imgData<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// testing... create data provider from file.... works</span>
	<span style="color: #11740a; font-style: italic;">//NSString* imageFileName = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@&quot;c.png&quot;];</span>
	<span style="color: #11740a; font-style: italic;">//CGDataProviderRef imgDataProvider = CGDataProviderCreateWithFilename([imageFileName UTF8String]);</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// does not work like that</span>
<span style="color: #11740a; font-style: italic;">// new image needs to get PNG properties</span>
<span style="color: #11740a; font-style: italic;">//CGImageRef throughCGImage = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// get PNG properties from cRef</span>
<span style="color: #a61390;">size_t</span> width <span style="color: #002200;">=</span> CGImageGetWidth<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
<span style="color: #a61390;">size_t</span> height <span style="color: #002200;">=</span> CGImageGetHeight<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
<span style="color: #a61390;">size_t</span> bitsPerComponent <span style="color: #002200;">=</span> CGImageGetBitsPerComponent<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
<span style="color: #a61390;">size_t</span> bitsPerPixel <span style="color: #002200;">=</span> CGImageGetBitsPerPixel<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
<span style="color: #a61390;">size_t</span> bytesPerRow <span style="color: #002200;">=</span> CGImageGetBytesPerRow<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
CGColorSpaceRef colorSpace <span style="color: #002200;">=</span> CGImageGetColorSpace<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
CGBitmapInfo info <span style="color: #002200;">=</span> CGImageGetBitmapInfo<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
CGFloat <span style="color: #002200;">*</span>decode <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;
<span style="color: #a61390;">BOOL</span> shouldInteroplate <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
CGColorRenderingIntent intent <span style="color: #002200;">=</span> CGImageGetRenderingIntent<span style="color: #002200;">&#40;</span>cRef<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// cRef PNG properties + imgDataProvider's data</span>
CGImageRef throughCGImage <span style="color: #002200;">=</span> CGImageCreate<span style="color: #002200;">&#40;</span>width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, info, imgDataProvider, decode, shouldInteroplate, intent<span style="color: #002200;">&#41;</span>;
CGDataProviderRelease<span style="color: #002200;">&#40;</span>imgDataProvider<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;c %i, throughCGImage: %i&quot;, CGImageGetHeight(cRef), CGImageGetHeight(throughCGImage) );</span>
CGImageRelease<span style="color: #002200;">&#40;</span>throughCGImage<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// make UIImage with CGImage</span>
UIImage<span style="color: #002200;">*</span> newImage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithCGImage<span style="color: #002200;">:</span>throughCGImage<span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">//NSLog(@&quot;newImage: %@&quot;, newImage);</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// draw UIImage</span>
<span style="color: #002200;">&#91;</span>newImage drawInRect<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">340</span>, <span style="color: #2400d9;">65</span>, <span style="color: #2400d9;">65</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>References:<br />
- <a href="http://iphoneincubator.com/blog/tag/cgimageref">http://iphoneincubator.com/blog/tag/cgimageref</a><br />
- <a href="http://www.nixwire.com/getting-uiimage-to-work-with-nscoding-encodewithcoder/">http://www.nixwire.com/getting-uiimage-to-work-with-nscoding-encodewithcoder/</a><br />
- <a href="http://developer.apple.com/mac/library/qa/qa2007/qa1509.html">http://developer.apple.com/mac/library/qa/qa2007/qa1509.html</a><br />
- <a href="http://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more">http://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more</a><br />
<strong>- <a href="http://lists.apple.com/archives/Quartz-dev/2008//Aug/msg00073.html">http://lists.apple.com/archives/Quartz-dev/2008//Aug/msg00073.html</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/347/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

