<?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>Chironex Software</title>
	<atom:link href="http://chironexsoftware.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://chironexsoftware.com/blog</link>
	<description>software development, making it work</description>
	<lastBuildDate>Wed, 13 Mar 2013 19:55:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>SC2 Loopback Free iOS</title>
		<link>http://chironexsoftware.com/blog/?p=89</link>
		<comments>http://chironexsoftware.com/blog/?p=89#comments</comments>
		<pubDate>Wed, 13 Mar 2013 19:55:22 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=89</guid>
		<description><![CDATA[A new free version of SC2 loopback is now available for iOS. - The full version has more channels available and no iAd banners]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=89"></g:plusone></div><p>A new free version of SC2 loopback is now available for iOS.</p>
<p><a href=https://itunes.apple.com/us/app/sc2-loopback-free/id605418571><br />
<img src="http://sc2loopback.com/sc2loopback/Images/platforms/Download_on_the_App_Store_Badge_US-UK_135x40_0801.png" alt="sc2 loopback app store" /><br />
</a></p>
<p>- The full version has more channels available and no iAd banners</p>
]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=89</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UIWebView to Image &#8211; iOS</title>
		<link>http://chironexsoftware.com/blog/?p=85</link>
		<comments>http://chironexsoftware.com/blog/?p=85#comments</comments>
		<pubDate>Tue, 29 Jan 2013 22:17:32 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Graphics\Animation programming]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=85</guid>
		<description><![CDATA[For a recent project I needed to save a UIWebView to an image. Including not just the visible area but the whole scrollable view. There are a number of example for creating a PDF from a webview, but I couldn&#8217;t find many example of converting to an Image. So below is a simple function to [...]]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=85"></g:plusone></div><p>For a recent project I needed to save a UIWebView to an image. Including not just the visible area but the whole scrollable view. There are a number of example for creating a PDF from a webview, but I couldn&#8217;t find many example of converting to an Image.</p>
<p>So below is a simple function to get it done. Includes some javascript calls to scroll the webview. This assumes the webview is created and visible to the user &#8211; again other example used a temporary uiwebview to render html content off screen.</p>
<p><code></p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Objective-C</span><div class="wp_syntax"><div class="code"><pre class="objc" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">&nbsp;
<span style="color: #CCC;">-</span> <span style="color: #CCC;">&#40;</span>UIImage<span style="color: #CCC;">*</span><span style="color: #CCC;">&#41;</span>webviewToImage<span style="color: #CCC;">:</span><span style="color: #CCC;">&#40;</span>UIWebView<span style="color: #CCC;">*</span><span style="color: #CCC;">&#41;</span>theWebView
<span style="color: #CCC;">&#123;</span>
    <span style="color: #99FFFF;">int</span> webViewHeight <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#91;</span>theWebView stringByEvaluatingJavaScriptFromString<span style="color: #CCC;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #7ACC00;">&quot;document.body.scrollHeight;&quot;</span><span style="color: #CCC;">&#93;</span> integerValue<span style="color: #CCC;">&#93;</span>;
    <span style="color: #99FFFF;">int</span> scrollByY <span style="color: #CCC;">=</span> theWebView.frame.size.height;
    <span style="color: #99FFFF;">int</span> imageName <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span>;
&nbsp;
    <span style="color: #CCC;">&#91;</span>theWebView stringByEvaluatingJavaScriptFromString<span style="color: #CCC;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #7ACC00;">&quot;window.scrollTo(0,0);&quot;</span><span style="color: #CCC;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSMutableArray</span><span style="color: #CCC;">*</span> images <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #CCC;">&#93;</span> init<span style="color: #CCC;">&#93;</span>;
&nbsp;
    CGRect screenRect <span style="color: #CCC;">=</span> theWebView.frame;
    <span style="color: #99FFFF;">double</span> currentWebViewHeight <span style="color: #CCC;">=</span> webViewHeight;
    <span style="color: #3D9EDD;">while</span> <span style="color: #CCC;">&#40;</span>currentWebViewHeight &gt; <span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span>
    <span style="color: #CCC;">&#123;</span>
        imageName <span style="color: #CCC;">++</span>;
&nbsp;
        UIGraphicsBeginImageContext<span style="color: #CCC;">&#40;</span>screenRect.size<span style="color: #CCC;">&#41;</span>;
        CGContextRef ctx <span style="color: #CCC;">=</span> UIGraphicsGetCurrentContext<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>;
        <span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#91;</span>UIColor blackColor<span style="color: #CCC;">&#93;</span> set<span style="color: #CCC;">&#93;</span>;
        CGContextFillRect<span style="color: #CCC;">&#40;</span>ctx, screenRect<span style="color: #CCC;">&#41;</span>;
&nbsp;
        <span style="color: #CCC;">&#91;</span>theWebView.layer renderInContext<span style="color: #CCC;">:</span>ctx<span style="color: #CCC;">&#93;</span>;
&nbsp;
        UIImage <span style="color: #CCC;">*</span>newImage <span style="color: #CCC;">=</span> UIGraphicsGetImageFromCurrentImageContext<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>;
        UIGraphicsEndImageContext<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>;
&nbsp;
        <span style="color: #3D9EDD;">if</span><span style="color: #CCC;">&#40;</span>currentWebViewHeight &lt; scrollByY<span style="color: #CCC;">&#41;</span>
        <span style="color: #CCC;">&#123;</span>
            CGRect lastImageRect <span style="color: #CCC;">=</span> CGRectMake<span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">0</span>, scrollByY <span style="color: #CCC;">-</span> currentWebViewHeight, theWebView.frame.size.width, currentWebViewHeight<span style="color: #CCC;">&#41;</span>;
            CGImageRef imageRef <span style="color: #CCC;">=</span> CGImageCreateWithImageInRect<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#91;</span>newImage CGImage<span style="color: #CCC;">&#93;</span>, lastImageRect<span style="color: #CCC;">&#41;</span>;
&nbsp;
            newImage <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#91;</span>UIImage imageWithCGImage<span style="color: #CCC;">:</span>imageRef<span style="color: #CCC;">&#93;</span>;
            CGImageRelease<span style="color: #CCC;">&#40;</span>imageRef<span style="color: #CCC;">&#41;</span>;
        <span style="color: #CCC;">&#125;</span>
        <span style="color: #CCC;">&#91;</span>images addObject<span style="color: #CCC;">:</span>newImage<span style="color: #CCC;">&#93;</span>;
&nbsp;
        <span style="color: #CCC;">&#91;</span>theWebView stringByEvaluatingJavaScriptFromString<span style="color: #CCC;">:</span><span style="color: #CCC;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #CCC;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #7ACC00;">&quot;window.scrollBy(0,%d);&quot;</span>, scrollByY<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">&#93;</span>;
        currentWebViewHeight <span style="color: #CCC;">-=</span> scrollByY;
    <span style="color: #CCC;">&#125;</span>
&nbsp;
    <span style="color: #CCC;">&#91;</span>theWebView stringByEvaluatingJavaScriptFromString<span style="color: #CCC;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #7ACC00;">&quot;window.scrollTo(0,0);&quot;</span><span style="color: #CCC;">&#93;</span>;
&nbsp;
    UIImage <span style="color: #CCC;">*</span>resultImage;
&nbsp;
    <span style="color: #3D9EDD;">if</span><span style="color: #CCC;">&#40;</span>images.count &gt; <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
        <span style="color: #33CC66;">//join all images together..</span>
        CGSize sz;
        <span style="color: #3D9EDD;">for</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> i<span style="color: #CCC;">=</span><span style="color: #FFCC00;">0</span>;i&lt;images.count;i<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
&nbsp;
            sz.width <span style="color: #CCC;">=</span> MAX<span style="color: #CCC;">&#40;</span>sz.width, <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span>UIImage<span style="color: #CCC;">*</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#91;</span>images objectAtIndex<span style="color: #CCC;">:</span>i<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">&#41;</span>.size.width <span style="color: #CCC;">&#41;</span>;
            sz.height <span style="color: #CCC;">+=</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span>UIImage<span style="color: #CCC;">*</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#91;</span>images objectAtIndex<span style="color: #CCC;">:</span>i<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">&#41;</span>.size.height;
        <span style="color: #CCC;">&#125;</span>
&nbsp;
        UIGraphicsBeginImageContext<span style="color: #CCC;">&#40;</span>sz<span style="color: #CCC;">&#41;</span>;
        CGContextRef ctx <span style="color: #CCC;">=</span> UIGraphicsGetCurrentContext<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>;
        <span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#91;</span>UIColor blackColor<span style="color: #CCC;">&#93;</span> set<span style="color: #CCC;">&#93;</span>;
        CGContextFillRect<span style="color: #CCC;">&#40;</span>ctx, screenRect<span style="color: #CCC;">&#41;</span>;
&nbsp;
        <span style="color: #99FFFF;">int</span> y<span style="color: #CCC;">=</span><span style="color: #FFCC00;">0</span>;
        <span style="color: #3D9EDD;">for</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> i<span style="color: #CCC;">=</span><span style="color: #FFCC00;">0</span>;i&lt;images.count;i<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
&nbsp;
            UIImage<span style="color: #CCC;">*</span> img <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#91;</span>images objectAtIndex<span style="color: #CCC;">:</span>i<span style="color: #CCC;">&#93;</span>;
            <span style="color: #CCC;">&#91;</span>img drawAtPoint<span style="color: #CCC;">:</span>CGPointMake<span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">0</span>,y<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#93;</span>;
            y <span style="color: #CCC;">+=</span> img.size.height;
        <span style="color: #CCC;">&#125;</span>
&nbsp;
        resultImage <span style="color: #CCC;">=</span> UIGraphicsGetImageFromCurrentImageContext<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>;
        UIGraphicsEndImageContext<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>;
    <span style="color: #CCC;">&#125;</span> <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span>
&nbsp;
        resultImage <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#91;</span>images objectAtIndex<span style="color: #CCC;">:</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#93;</span>;
    <span style="color: #CCC;">&#125;</span>
&nbsp;
    <span style="color: #3D9EDD;">return</span> resultImage;
&nbsp;
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=85</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy New Year &#8211; SC2 Loopback free for a week</title>
		<link>http://chironexsoftware.com/blog/?p=81</link>
		<comments>http://chironexsoftware.com/blog/?p=81#comments</comments>
		<pubDate>Mon, 31 Dec 2012 22:32:40 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=81</guid>
		<description><![CDATA[To kick off the new year SC2 Loopback is free for download for one week! http://www.sc2loopback.com Grab your copy now and enjoy the latest star craft videos on your iOS devices.]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=81"></g:plusone></div><p>To kick off the new year SC2 Loopback is free for download for one week! </p>
<p>http://www.sc2loopback.com</p>
<p>Grab your copy now and enjoy the latest star craft videos on your iOS devices.</p>
]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=81</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One widow playing cards</title>
		<link>http://chironexsoftware.com/blog/?p=77</link>
		<comments>http://chironexsoftware.com/blog/?p=77#comments</comments>
		<pubDate>Thu, 25 Oct 2012 20:31:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=77</guid>
		<description><![CDATA[Some cool designs on the age old playing cards. Check them out, makes a great xmas idea. More apps and poker related software is in development so stay tuned! onwidow.com]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=77"></g:plusone></div><p>Some cool designs on the age old playing cards. Check them out, makes a great xmas idea. More apps and poker related software is in development so stay tuned!</p>
<p><a href="http://www.onewidow.com/collections/decks"> onwidow.com</p>
<p><img src="http://cdn.shopify.com/s/files/1/0065/1632/products/onewidow__02_main01_1024x1024.jpg?0" alt="one widow playing cards" /></p>
<p></a></p>
]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=77</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SC2 Loopback App</title>
		<link>http://chironexsoftware.com/blog/?p=73</link>
		<comments>http://chironexsoftware.com/blog/?p=73#comments</comments>
		<pubDate>Sat, 20 Oct 2012 06:03:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=73</guid>
		<description><![CDATA[Just released a new app in the app store. A small iOS app for watching starcraft replays and videos. http://ww.sc2loopback.com/ Its simple app that uses some external api&#8217;s and developed with xcode, supporting iOS 4.2 on iPhones and iPads. I&#8217;ll be releasing an Android version soon and maybe a windows desktop and metro version as [...]]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=73"></g:plusone></div><p>Just released a new app in the app store. A small iOS app for watching starcraft replays and videos.<br />
<a href="http://ww.sc2loopback.com/">http://ww.sc2loopback.com/</a></p>
<p>Its simple app that uses some external api&#8217;s and developed with xcode, supporting iOS 4.2 on iPhones and iPads. I&#8217;ll be releasing an Android version soon and maybe a windows desktop and metro version as well.<br />
<a href=https://itunes.apple.com/us/app/sc2-loopback/id569366415><br />
<img src="http://sc2loopback.com/sc2loopback/Images/platforms/Download_on_the_App_Store_Badge_US-UK_135x40_0801.png" alt="sc2 loopback app store" /><br />
</a></p>
<p><img src="http://sc2loopback.com/sc2loopback/Images/devices.png" alt="sc2 loopback" /></p>
]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=73</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 5 Slider Binding Bug</title>
		<link>http://chironexsoftware.com/blog/?p=69</link>
		<comments>http://chironexsoftware.com/blog/?p=69#comments</comments>
		<pubDate>Thu, 04 Oct 2012 18:40:50 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=69</guid>
		<description><![CDATA[As described here http://forums.silverlight.net/t/119338.aspx/1 Silverlight 5 (and 4) has a bug with it&#8217;s slider control. You can not bind to the Maximum and Minimum properties of the control. To get around this I have a simple solution with the code below. Basically just inherit from Slider and add two custom dependency properties and register for [...]]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=69"></g:plusone></div><p>As described here<br />
<a href="http://forums.silverlight.net/t/119338.aspx/1">http://forums.silverlight.net/t/119338.aspx/1</a></p>
<p>Silverlight 5 (and 4) has a bug with it&#8217;s slider control. You can not bind to the Maximum and Minimum properties of the control. To get around this I have a simple solution with the code below. Basically just inherit from Slider and add two custom dependency properties and register for the on-changed events. In the callback you can manually set the minimum and maximum values of the slider instead of bindings.</p>
<p>This is a pain but seems to be a easy and clean solutions.</p>
<p><code></p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">&nbsp;
<span style="color: #3D9EDD;">public</span> <span style="color: #99FFFF;">class</span> CustomSlider <span style="color: #CCC;">:</span> Slider
    <span style="color: #CCC;">&#123;</span>
&nbsp;
        <span style="color: #3D9EDD;">public</span> <span style="color: #3D9EDD;">static</span> <span style="color: #3D9EDD;">readonly</span> DependencyProperty MinimumBugFixProperty <span style="color: #CCC;">=</span> DependencyProperty<span style="color: #CCC;">.</span><span style="color: #FFF;">Register</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;MinimumBugFix&quot;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">double</span><span style="color: #CCC;">&#41;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>CustomSlider<span style="color: #CCC;">&#41;</span>, <span style="color: #996699;">new</span> FrameworkPropertyMetadata<span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">0</span>, <span style="color: #996699;">new</span> PropertyChangedCallback<span style="color: #CCC;">&#40;</span>OnUpdateSliderRange<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
        <span style="color: #3D9EDD;">public</span> <span style="color: #3D9EDD;">static</span> <span style="color: #3D9EDD;">readonly</span> DependencyProperty MaximumBugFixProperty <span style="color: #CCC;">=</span> DependencyProperty<span style="color: #CCC;">.</span><span style="color: #FFF;">Register</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;MaximumBugFix&quot;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">double</span><span style="color: #CCC;">&#41;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>CustomSlider<span style="color: #CCC;">&#41;</span>, <span style="color: #996699;">new</span> FrameworkPropertyMetadata<span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">100</span>, <span style="color: #996699;">new</span> PropertyChangedCallback<span style="color: #CCC;">&#40;</span>OnUpdateSliderRange<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
&nbsp;
        <span style="color: #3D9EDD;">public</span> CustomSlider<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>
        <span style="color: #CCC;">&#123;</span>
&nbsp;
        <span style="color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #3D9EDD;">public</span> <span style="color: #99FFFF;">double</span> MinimumBugFix
        <span style="color: #CCC;">&#123;</span>
            get <span style="color: #CCC;">&#123;</span> <span style="color: #3D9EDD;">return</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">double</span><span style="color: #CCC;">&#41;</span>GetValue<span style="color: #CCC;">&#40;</span>MinimumBugFixProperty<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #CCC;">&#125;</span>
            set <span style="color: #CCC;">&#123;</span> SetValue<span style="color: #CCC;">&#40;</span>MinimumBugFixProperty, value<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #CCC;">&#125;</span>
        <span style="color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #3D9EDD;">public</span> <span style="color: #99FFFF;">double</span> MaximumBugFix
        <span style="color: #CCC;">&#123;</span>
            get <span style="color: #CCC;">&#123;</span> <span style="color: #3D9EDD;">return</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">double</span><span style="color: #CCC;">&#41;</span>GetValue<span style="color: #CCC;">&#40;</span>MaximumBugFixProperty<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #CCC;">&#125;</span>
            set <span style="color: #CCC;">&#123;</span> SetValue<span style="color: #CCC;">&#40;</span>MaximumBugFixProperty, value<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #CCC;">&#125;</span>
        <span style="color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #3D9EDD;">private</span> <span style="color: #3D9EDD;">static</span> <span style="color: #99FFFF;">void</span> OnUpdateSliderRange<span style="color: #CCC;">&#40;</span>DependencyObject d, DependencyPropertyChangedEventArgs e<span style="color: #CCC;">&#41;</span>
        <span style="color: #CCC;">&#123;</span>
            CustomSlider slider <span style="color: #CCC;">=</span> d <span style="color: #3D9EDD;">as</span> CustomSlider<span style="color: #CCC;">;</span>
            <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>slider <span style="color: #CCC;">!=</span> <span style="color: #3D9EDD;">null</span><span style="color: #CCC;">&#41;</span>
            <span style="color: #CCC;">&#123;</span>
                <span style="color: #3D9EDD;">if</span><span style="color: #CCC;">&#40;</span>slider<span style="color: #CCC;">.</span><span style="color: #FFF;">Maximum</span> <span style="color: #CCC;">!=</span> slider<span style="color: #CCC;">.</span><span style="color: #FFF;">MaximumBugFix</span><span style="color: #CCC;">&#41;</span>
                    slider<span style="color: #CCC;">.</span><span style="color: #FFF;">Maximum</span> <span style="color: #CCC;">=</span> slider<span style="color: #CCC;">.</span><span style="color: #FFF;">MaximumBugFix</span><span style="color: #CCC;">;</span>
                <span style="color: #3D9EDD;">if</span><span style="color: #CCC;">&#40;</span>slider<span style="color: #CCC;">.</span><span style="color: #FFF;">Minimum</span> <span style="color: #CCC;">!=</span> slider<span style="color: #CCC;">.</span><span style="color: #FFF;">MinimumBugFix</span><span style="color: #CCC;">&#41;</span>
                    slider<span style="color: #CCC;">.</span><span style="color: #FFF;">Minimum</span> <span style="color: #CCC;">=</span> slider<span style="color: #CCC;">.</span><span style="color: #FFF;">MinimumBugFix</span><span style="color: #CCC;">;</span>
            <span style="color: #CCC;">&#125;</span>
        <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=69</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF to Silverlight porting&#8230;</title>
		<link>http://chironexsoftware.com/blog/?p=64</link>
		<comments>http://chironexsoftware.com/blog/?p=64#comments</comments>
		<pubDate>Wed, 08 Feb 2012 23:23:28 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=64</guid>
		<description><![CDATA[My biggest WTF moment so far with silverlight.. there is no Visibility.Hidden enum value. So much for reusing all those valueconverters.. oh the pain! C#&#160; namespace System.Windows &#123; // Summary: // Specifies the display state of an element. public enum Visibility &#123; // Summary: // Display the element. Visible = 0, // // Summary: // [...]]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=64"></g:plusone></div><p>My biggest WTF moment so far with silverlight.. there is no Visibility.Hidden enum value.</p>
<p>So much for reusing all those valueconverters.. oh the pain!</p>
<p><code></p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">&nbsp;
<span style="color: #3D9EDD;">namespace</span> <span style="color: #000000;">System</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Windows</span>
<span style="color: #CCC;">&#123;</span>
    <span style="color: #999;">// Summary:</span>
    <span style="color: #999;">//     Specifies the display state of an element.</span>
    <span style="color: #3D9EDD;">public</span> <span style="color: #99FFFF;">enum</span> Visibility
    <span style="color: #CCC;">&#123;</span>
        <span style="color: #999;">// Summary:</span>
        <span style="color: #999;">//     Display the element.</span>
        Visible <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span>,
        <span style="color: #999;">//</span>
        <span style="color: #999;">// Summary:</span>
        <span style="color: #999;">//     Do not display the element, and do not reserve space for it in layout.</span>
        Collapsed <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1</span>,
    <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=64</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calculate Dominant Color of Bitmap</title>
		<link>http://chironexsoftware.com/blog/?p=60</link>
		<comments>http://chironexsoftware.com/blog/?p=60#comments</comments>
		<pubDate>Thu, 01 Dec 2011 09:57:17 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Graphics\Animation programming]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=60</guid>
		<description><![CDATA[The code section below is an example of how to calculate the dominant color in a bitmap. The code uses euclidean distance calculations for each color channel in each pixel. Then it sorts the pixels to find the color which is the closest to all other colors. To improve the output I take to top [...]]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=60"></g:plusone></div><p>The code section below is an example of how to calculate the dominant color in a bitmap. The code uses euclidean distance calculations for each color channel in each pixel. Then it sorts the pixels to find the color which is the closest to all other colors.</p>
<p>To improve the output I take to top %2 of colors and average them. Also the Alpha channel is treated differently though it could be changed to use the same distance logic.</p>
<p>The results are much better than the average color calculation. Though it is more computationally expensive so it will take longer to complete.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #CCC;">&lt;</span>code<span style="color: #CCC;">&gt;</span>
&nbsp;
<span style="color: #3D9EDD;">public</span> <span style="color: #3D9EDD;">static</span> Color CalculateDominantColor<span style="color: #CCC;">&#40;</span>BitmapSource source<span style="color: #CCC;">&#41;</span>
        <span style="color: #CCC;">&#123;</span>
            <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span><span style="color: #CCC;">.</span><span style="color: #FFF;">BitsPerPixel</span> <span style="color: #CCC;">!=</span> <span style="color: #FFCC00;">32</span> <span style="color: #CCC;">||</span> source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span> <span style="color: #CCC;">!=</span> PixelFormats<span style="color: #CCC;">.</span><span style="color: #FFF;">Bgra32</span><span style="color: #CCC;">&#41;</span>
                <span style="color: #3D9EDD;">throw</span> <span style="color: #996699;">new</span> ApplicationException<span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;expected 32bit image&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
&nbsp;
            Dictionary<span style="color: #CCC;">&lt;</span>Color, <span style="color: #99FFFF;">double</span><span style="color: #CCC;">&gt;</span> colorDist <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> Dictionary<span style="color: #CCC;">&lt;</span>Color, <span style="color: #99FFFF;">double</span><span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #000000;">System</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Windows</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Size</span> sz <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> <span style="color: #000000;">System</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Windows</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Size</span><span style="color: #CCC;">&#40;</span>source<span style="color: #CCC;">.</span><span style="color: #FFF;">PixelWidth</span>, source<span style="color: #CCC;">.</span><span style="color: #FFF;">PixelHeight</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #999;">//read bitmap </span>
            <span style="color: #99FFFF;">int</span> pixelsSz <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span>sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span> <span style="color: #CCC;">*</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span>sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Height</span> <span style="color: #CCC;">*</span> <span style="color: #CCC;">&#40;</span>source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span><span style="color: #CCC;">.</span><span style="color: #FFF;">BitsPerPixel</span> <span style="color: #CCC;">/</span> <span style="color: #FFCC00;">8</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
            <span style="color: #99FFFF;">int</span> stride <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span>sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span> <span style="color: #CCC;">*</span> source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span><span style="color: #CCC;">.</span><span style="color: #FFF;">BitsPerPixel</span> <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">7</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">/</span> <span style="color: #FFCC00;">8</span><span style="color: #CCC;">;</span>
            <span style="color: #99FFFF;">int</span> pixelBytes <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span>source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span><span style="color: #CCC;">.</span><span style="color: #FFF;">BitsPerPixel</span> <span style="color: #CCC;">/</span> <span style="color: #FFCC00;">8</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#93;</span> pixels <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> <span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#91;</span>pixelsSz<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
            source<span style="color: #CCC;">.</span><span style="color: #FFF;">CopyPixels</span><span style="color: #CCC;">&#40;</span>pixels, stride, <span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #3D9EDD;">const</span> <span style="color: #99FFFF;">int</span> alphaThershold <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">10</span><span style="color: #CCC;">;</span>
            UInt64 pixelCount <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
            UInt64 avgAlpha <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #3D9EDD;">for</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> y <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> y <span style="color: #CCC;">&lt;</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Height</span><span style="color: #CCC;">;</span> y<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span>
            <span style="color: #CCC;">&#123;</span>
                <span style="color: #3D9EDD;">for</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> x <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> x <span style="color: #CCC;">&lt;</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span><span style="color: #CCC;">;</span> x<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span>
                <span style="color: #CCC;">&#123;</span>
                    <span style="color: #99FFFF;">int</span> index <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span>y <span style="color: #CCC;">*</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> x<span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">*</span> <span style="color: #CCC;">&#40;</span>pixelBytes<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
                    <span style="color: #99FFFF;">byte</span> r1, g1, b1, a1<span style="color: #CCC;">;</span> r1 <span style="color: #CCC;">=</span> g1 <span style="color: #CCC;">=</span> b1 <span style="color: #CCC;">=</span> a1 <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
                    a1 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">3</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                    r1 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                    g1 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                    b1 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
&nbsp;
                    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>a1 <span style="color: #CCC;">&lt;=</span> alphaThershold<span style="color: #CCC;">&#41;</span>
                        <span style="color: #3D9EDD;">continue</span><span style="color: #CCC;">;</span> <span style="color: #999;">//ignore</span>
&nbsp;
                    pixelCount<span style="color: #CCC;">++;</span>
                    avgAlpha <span style="color: #CCC;">+=</span> <span style="color: #CCC;">&#40;</span>UInt64<span style="color: #CCC;">&#41;</span>a1<span style="color: #CCC;">;</span>
&nbsp;
                    Color cl <span style="color: #CCC;">=</span> Color<span style="color: #CCC;">.</span><span style="color: #FFF;">FromArgb</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">0</span>, r1, g1, b1<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
                    <span style="color: #99FFFF;">double</span> dist <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
                    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">!</span>colorDist<span style="color: #CCC;">.</span><span style="color: #FFF;">ContainsKey</span><span style="color: #CCC;">&#40;</span>cl<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span>
                    <span style="color: #CCC;">&#123;</span>
                        colorDist<span style="color: #CCC;">.</span><span style="color: #FFF;">Add</span><span style="color: #CCC;">&#40;</span>cl, <span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
                        <span style="color: #3D9EDD;">for</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> y2 <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> y2 <span style="color: #CCC;">&lt;</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Height</span><span style="color: #CCC;">;</span> y2<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span>
                        <span style="color: #CCC;">&#123;</span>
                            <span style="color: #3D9EDD;">for</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> x2 <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> x2 <span style="color: #CCC;">&lt;</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span><span style="color: #CCC;">;</span> x2<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span>
                            <span style="color: #CCC;">&#123;</span>
                                <span style="color: #99FFFF;">int</span> index2 <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>y2 <span style="color: #CCC;">*</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> x2<span style="color: #CCC;">;</span>
                                <span style="color: #99FFFF;">byte</span> r2, g2, b2, a2<span style="color: #CCC;">;</span> r2 <span style="color: #CCC;">=</span> g2 <span style="color: #CCC;">=</span> b2 <span style="color: #CCC;">=</span> a2 <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
                                a2 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index2 <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">3</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                                r2 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index2 <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                                g2 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index2 <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                                b2 <span style="color: #CCC;">=</span> pixels<span style="color: #CCC;">&#91;</span>index2<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
&nbsp;
                                <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>a2 <span style="color: #CCC;">&lt;=</span> alphaThershold<span style="color: #CCC;">&#41;</span>
                                    <span style="color: #3D9EDD;">continue</span><span style="color: #CCC;">;</span> <span style="color: #999;">//ignore</span>
&nbsp;
                                dist <span style="color: #CCC;">+=</span> Math<span style="color: #CCC;">.</span><span style="color: #FFF;">Sqrt</span><span style="color: #CCC;">&#40;</span>Math<span style="color: #CCC;">.</span><span style="color: #FFF;">Pow</span><span style="color: #CCC;">&#40;</span>r2 <span style="color: #CCC;">-</span> r1, <span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> 
                                                  Math<span style="color: #CCC;">.</span><span style="color: #FFF;">Pow</span><span style="color: #CCC;">&#40;</span>g2 <span style="color: #CCC;">-</span> g1, <span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> 
                                                  Math<span style="color: #CCC;">.</span><span style="color: #FFF;">Pow</span><span style="color: #CCC;">&#40;</span>b2 <span style="color: #CCC;">-</span> b1, <span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
                            <span style="color: #CCC;">&#125;</span>
                        <span style="color: #CCC;">&#125;</span>
&nbsp;
                        colorDist<span style="color: #CCC;">&#91;</span>cl<span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">=</span> dist<span style="color: #CCC;">;</span>
                    <span style="color: #CCC;">&#125;</span>
                <span style="color: #CCC;">&#125;</span>
            <span style="color: #CCC;">&#125;</span>
&nbsp;
            <span style="color: #999;">//clamp alpha</span>
            avgAlpha <span style="color: #CCC;">=</span> avgAlpha <span style="color: #CCC;">/</span> pixelCount<span style="color: #CCC;">;</span>
            <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>avgAlpha <span style="color: #CCC;">&gt;=</span> <span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">255</span> <span style="color: #CCC;">-</span> alphaThershold<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span>
                avgAlpha <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">255</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #999;">//take weighted average of top 2% of colors         </span>
            var clrs <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #3D9EDD;">from</span> entry <span style="color: #3D9EDD;">in</span> colorDist
                        orderby entry<span style="color: #CCC;">.</span><span style="color: #FFF;">Value</span> ascending
                        <span style="color: #3D9EDD;">select</span> <span style="color: #996699;">new</span> <span style="color: #CCC;">&#123;</span> Color <span style="color: #CCC;">=</span> entry<span style="color: #CCC;">.</span><span style="color: #FFF;">Key</span>, Dist <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1.0</span><span style="color: #CCC;">/</span>Math<span style="color: #CCC;">.</span><span style="color: #FFF;">Max</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">1</span>,entry<span style="color: #CCC;">.</span><span style="color: #FFF;">Value</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#125;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">.</span><span style="color: #FFF;">ToList</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Take</span><span style="color: #CCC;">&#40;</span> Math<span style="color: #CCC;">.</span><span style="color: #FFF;">Max</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">1</span>, <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>colorDist<span style="color: #CCC;">.</span><span style="color: #FFF;">Count</span> <span style="color: #CCC;">*</span> <span style="color: #FFCC00;">0.02</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #99FFFF;">double</span> sumDist <span style="color: #CCC;">=</span> clrs<span style="color: #CCC;">.</span><span style="color: #FFF;">Sum</span><span style="color: #CCC;">&#40;</span>x <span style="color: #CCC;">=&gt;</span> x<span style="color: #CCC;">.</span><span style="color: #FFF;">Dist</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
            Color result <span style="color: #CCC;">=</span> Color<span style="color: #CCC;">.</span><span style="color: #FFF;">FromArgb</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#41;</span>avgAlpha,
                                          <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>clrs<span style="color: #CCC;">.</span><span style="color: #FFF;">Sum</span><span style="color: #CCC;">&#40;</span>x <span style="color: #CCC;">=&gt;</span> x<span style="color: #CCC;">.</span><span style="color: #FFF;">Color</span><span style="color: #CCC;">.</span><span style="color: #FFF;">R</span> <span style="color: #CCC;">*</span> x<span style="color: #CCC;">.</span><span style="color: #FFF;">Dist</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">/</span> sumDist<span style="color: #CCC;">&#41;</span>,
                                          <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>clrs<span style="color: #CCC;">.</span><span style="color: #FFF;">Sum</span><span style="color: #CCC;">&#40;</span>x <span style="color: #CCC;">=&gt;</span> x<span style="color: #CCC;">.</span><span style="color: #FFF;">Color</span><span style="color: #CCC;">.</span><span style="color: #FFF;">G</span> <span style="color: #CCC;">*</span> x<span style="color: #CCC;">.</span><span style="color: #FFF;">Dist</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">/</span> sumDist<span style="color: #CCC;">&#41;</span>,
                                          <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>clrs<span style="color: #CCC;">.</span><span style="color: #FFF;">Sum</span><span style="color: #CCC;">&#40;</span>x <span style="color: #CCC;">=&gt;</span> x<span style="color: #CCC;">.</span><span style="color: #FFF;">Color</span><span style="color: #CCC;">.</span><span style="color: #FFF;">B</span> <span style="color: #CCC;">*</span> x<span style="color: #CCC;">.</span><span style="color: #FFF;">Dist</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">/</span> sumDist<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #3D9EDD;">return</span> result<span style="color: #CCC;">;</span>
        <span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #CCC;">&lt;/</span>code<span style="color: #CCC;">&gt;</span></pre></div></div></div>

]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=60</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF easy bitmap resize</title>
		<link>http://chironexsoftware.com/blog/?p=55</link>
		<comments>http://chironexsoftware.com/blog/?p=55#comments</comments>
		<pubDate>Thu, 01 Dec 2011 09:51:20 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Graphics\Animation programming]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=55</guid>
		<description><![CDATA[Here is an example of a really easy way to resize a bitmap using WPF imaging classes. C#&#60;code&#62; &#160; public static BitmapSource ResizeBitmap&#40;BitmapSource source, int nWidth, int nHeight&#41; &#123; TransformedBitmap tbBitmap = new TransformedBitmap&#40;source, new ScaleTransform&#40;nWidth / source.PixelWidth, nHeight / source.PixelHeight, 0, 0&#41;&#41;; return tbBitmap; &#125; &#160; &#160; &#60;/code&#62;]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=55"></g:plusone></div><p>Here is an example of a really easy way to resize a bitmap using WPF imaging classes.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #CCC;">&lt;</span>code<span style="color: #CCC;">&gt;</span>
&nbsp;
 <span style="color: #3D9EDD;">public</span> <span style="color: #3D9EDD;">static</span> BitmapSource ResizeBitmap<span style="color: #CCC;">&#40;</span>BitmapSource source, <span style="color: #99FFFF;">int</span> nWidth, <span style="color: #99FFFF;">int</span> nHeight<span style="color: #CCC;">&#41;</span>
 <span style="color: #CCC;">&#123;</span>
   TransformedBitmap tbBitmap <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> TransformedBitmap<span style="color: #CCC;">&#40;</span>source,
                                             <span style="color: #996699;">new</span> ScaleTransform<span style="color: #CCC;">&#40;</span>nWidth <span style="color: #CCC;">/</span> source<span style="color: #CCC;">.</span><span style="color: #FFF;">PixelWidth</span>,
                                                                nHeight <span style="color: #CCC;">/</span> source<span style="color: #CCC;">.</span><span style="color: #FFF;">PixelHeight</span>,
                                                                <span style="color: #FFCC00;">0</span>, <span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
   <span style="color: #3D9EDD;">return</span> tbBitmap<span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #CCC;">&lt;/</span>code<span style="color: #CCC;">&gt;</span></pre></div></div></div>

]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=55</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF C#, CalculateAverageColor for bitmap</title>
		<link>http://chironexsoftware.com/blog/?p=47</link>
		<comments>http://chironexsoftware.com/blog/?p=47#comments</comments>
		<pubDate>Wed, 23 Nov 2011 10:29:08 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Graphics\Animation programming]]></category>
		<category><![CDATA[Windows Developement]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[WBF]]></category>

		<guid isPermaLink="false">http://chironexsoftware.com/blog/?p=47</guid>
		<description><![CDATA[Here is a simple method to calculate the average color in a bitmap (WPF C#). The result is not always the best, it can tend to be muddy or more like a grey-scale effect. An improved method is to find the dominant color, though more computationally expensive &#8211; I will post an example soon. C#&#60;code&#62; [...]]]></description>
			<content:encoded><![CDATA[<div class="google_plus_one"><g:plusone size="small" count="false" url="http://chironexsoftware.com/blog/?p=47"></g:plusone></div><p>Here is a simple method to calculate the average color in a bitmap (WPF C#). The result is not always the best, it can tend to be muddy or more like a grey-scale effect. An improved method is to find the dominant color, though more computationally expensive &#8211; I will post an example soon.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #CCC;">&lt;</span>code<span style="color: #CCC;">&gt;</span>
&nbsp;
<span style="color: #3D9EDD;">public</span> <span style="color: #3D9EDD;">static</span> Color CalculateAverageColor<span style="color: #CCC;">&#40;</span>BitmapSource source<span style="color: #CCC;">&#41;</span>
        <span style="color: #CCC;">&#123;</span>
            <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span><span style="color: #CCC;">.</span><span style="color: #FFF;">BitsPerPixel</span> <span style="color: #CCC;">!=</span> <span style="color: #FFCC00;">32</span><span style="color: #CCC;">&#41;</span>
                <span style="color: #3D9EDD;">throw</span> <span style="color: #996699;">new</span> ApplicationException<span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;expected 32bit image&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            Color cl<span style="color: #CCC;">;</span>
            <span style="color: #000000;">System</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Windows</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Size</span> sz <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> <span style="color: #000000;">System</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Windows</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Size</span><span style="color: #CCC;">&#40;</span>source<span style="color: #CCC;">.</span><span style="color: #FFF;">PixelWidth</span>, source<span style="color: #CCC;">.</span><span style="color: #FFF;">PixelHeight</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #999;">//read bitmap </span>
            <span style="color: #99FFFF;">int</span> pixelsSz <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span>sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span> <span style="color: #CCC;">*</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span>sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Height</span> <span style="color: #CCC;">*</span> <span style="color: #CCC;">&#40;</span>source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span><span style="color: #CCC;">.</span><span style="color: #FFF;">BitsPerPixel</span> <span style="color: #CCC;">/</span> <span style="color: #FFCC00;">8</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
            <span style="color: #99FFFF;">int</span> stride <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span>sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span> <span style="color: #CCC;">*</span> source<span style="color: #CCC;">.</span><span style="color: #FFF;">Format</span><span style="color: #CCC;">.</span><span style="color: #FFF;">BitsPerPixel</span> <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">7</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">/</span> <span style="color: #FFCC00;">8</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#93;</span> pixels <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> <span style="color: #99FFFF;">byte</span><span style="color: #CCC;">&#91;</span>pixelsSz<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
            source<span style="color: #CCC;">.</span><span style="color: #FFF;">CopyPixels</span><span style="color: #CCC;">&#40;</span>pixels, stride, <span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #999;">//find the average color for the image</span>
            <span style="color: #3D9EDD;">const</span> <span style="color: #99FFFF;">int</span> alphaThershold <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">10</span><span style="color: #CCC;">;</span>
            UInt64 r, g, b, a<span style="color: #CCC;">;</span> r <span style="color: #CCC;">=</span> g <span style="color: #CCC;">=</span> b <span style="color: #CCC;">=</span> a <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
            UInt64 pixelCount <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #3D9EDD;">for</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> y <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> y <span style="color: #CCC;">&lt;</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Height</span><span style="color: #CCC;">;</span> y<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span>
            <span style="color: #CCC;">&#123;</span>
                <span style="color: #3D9EDD;">for</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> x <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> x <span style="color: #CCC;">&lt;</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span><span style="color: #CCC;">;</span> x<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span>
                <span style="color: #CCC;">&#123;</span>
                    <span style="color: #99FFFF;">int</span> index <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span>y <span style="color: #CCC;">*</span> sz<span style="color: #CCC;">.</span><span style="color: #FFF;">Width</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> x<span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">*</span> <span style="color: #FFCC00;">4</span><span style="color: #CCC;">;</span>
                    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>pixels<span style="color: #CCC;">&#91;</span>index <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">3</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">&lt;=</span> alphaThershold<span style="color: #CCC;">&#41;</span> <span style="color: #999;">//ignore transparent</span>
                        <span style="color: #3D9EDD;">continue</span><span style="color: #CCC;">;</span>
&nbsp;
                    pixelCount<span style="color: #CCC;">++;</span>
                    a <span style="color: #CCC;">+=</span> pixels<span style="color: #CCC;">&#91;</span>index <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">3</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                    r <span style="color: #CCC;">+=</span> pixels<span style="color: #CCC;">&#91;</span>index <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                    g <span style="color: #CCC;">+=</span> pixels<span style="color: #CCC;">&#91;</span>index <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                    b <span style="color: #CCC;">+=</span> pixels<span style="color: #CCC;">&#91;</span>index<span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
                <span style="color: #CCC;">&#125;</span>
            <span style="color: #CCC;">&#125;</span>
&nbsp;
            <span style="color: #999;">//average color result</span>
            cl <span style="color: #CCC;">=</span> Color<span style="color: #CCC;">.</span><span style="color: #FFF;">FromArgb</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>a <span style="color: #CCC;">/</span> pixelCount<span style="color: #CCC;">&#41;</span>,
                                <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>r <span style="color: #CCC;">/</span> pixelCount<span style="color: #CCC;">&#41;</span>,
                                <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>g <span style="color: #CCC;">/</span> pixelCount<span style="color: #CCC;">&#41;</span>,
                                <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#40;</span>b <span style="color: #CCC;">/</span> pixelCount<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
            <span style="color: #3D9EDD;">return</span> cl<span style="color: #CCC;">;</span>           
        <span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #CCC;">&lt;/</span>code<span style="color: #CCC;">&gt;</span></pre></div></div></div>

]]></content:encoded>
			<wfw:commentRss>http://chironexsoftware.com/blog/?feed=rss2&#038;p=47</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
