Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've got three 'hacks' to suggest for now:</p> <h2>Hack #1</h2> <p>To force the extent to trim the image by replacing this line:</p> <pre><code>var cgimage = context.CreateCGImage(output, output.Extent); </code></pre> <p>with this:</p> <pre><code>var extent = output.Extent; if (UIScreen.MainScreen.RespondsToSelector (new MonoTouch.ObjCRuntime.Selector("scale"))) { if (UIScreen.MainScreen.Scale == 2f) { extent = new System.Drawing.RectangleF(extent.X, extent.Y, extent.Width / 2f, extent.Height / 2f); } } var cgimage = context.CreateCGImage(output, extent); </code></pre> <p>HOWEVER you 'lose' the Retina resolution on the adjusted image (it uses the @2x image as the source, but only displays the bottom-left quadrant of it after applying the filter, thanks to the image origin starting at the bottom-left).</p> <h2>Hack #2</h2> <p>Along the same lines, you can scale the image returned from the <code>ChangeHue</code> method so that it doesn't expand beyond the navigation bar:</p> <pre><code>var hued = ChangeHue (navBarImage); if (hued.RespondsToSelector(new MonoTouch.ObjCRuntime.Selector("scale"))) hued = hued.Scale (new System.Drawing.SizeF(320, 47)); UINavigationBar.Appearance.SetBackgroundImage (hued, UIBarMetrics.Default); </code></pre> <p>UNFORTUNATELY you 'lose' the Retina resolution again, but at least the image is displayed correctly (just downsampled to 320 wide).</p> <h2>Hack #3</h2> <p>You could save the filtered image to disk and then set the <code>UIAppearance</code> using the image file on 'disk'. The code would look like this:</p> <pre><code>bool retina = false; if (UIScreen.MainScreen.RespondsToSelector (new MonoTouch.ObjCRuntime.Selector ("scale"))) { if (UIScreen.MainScreen.Scale == 2f) { retina = true; } } if (retina) { NSError err; // unitialized UIImage img = ChangeHue (navBarImage); img.AsPNG ().Save ("tempNavBar@2x.png", true, out err); if (err != null &amp;&amp; err.Code != 0) { // error handling } UINavigationBar.Appearance.SetBackgroundImage (UIImage.FromFile ("tempNavBar.png"), UIBarMetrics.Default); } else { UINavigationBar.Appearance.SetBackgroundImage (ChangeHue (navBarImage), UIBarMetrics.Default); } </code></pre> <p>The benefit of this final hack is that the image looks correct (ie. Retina resolution is preserved).</p> <p>I'm still looking for the "perfect" solution, but at least these ideas 'fix' your problem one-way-or-another...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload