Canvas and Nine Patch Bug?
<p>I'm use a NinePatch to draw to a Canvas. The Bitmap that the Canvas is drawing to is 1024px by 128px. However, no matter where I start drawing the NinePatch or how wide it is, the NinePatch will not draw beyond 550px on the X-Axis.</p>

<p>Here is the NinePatch image I am using.</p>

<p><img src="http://i.stack.imgur.com/6pWko.png" alt="NinePatch PNG"></p>

<p>And here is a direct FileOutputStream of the Bitmap that is created and drawn to. The NinePatch is trying to draw from (500, 0) to (1024, 128).</p>

<p><img src="http://i.stack.imgur.com/fdRlO.png" alt="NinePatch Error or Bug"></p>

<p>I fill the entire bitmap with a slightly opaque value of ARGB(32, 255, 0, 0) to easily see the bounds of the Bitmap.</p>

<p>Here is a snippet of code that is doing the drawing:</p>

<pre><code>// Create a bitmap
Bitmap texture_bmp = Bitmap.createBitmap(1024, 128, DEFAULT_BITMAP_CONFIG);
mCanvas.setBitmap(texture_bmp);
mCanvas.drawARGB(32, 255, 0, 0); //Fill with color to see bitmap easily

Bitmap nine_patch_bmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.test_nine_patch);
NinePatch my_nine_patch = new NinePatch(nine_patch_bmp, nine_patch_bmp.getNinePatchChunk(), null);
my_nine_patch.draw(mCanvas, new Rect(500, 0, 1024, 128));

// Write texture to file ...
</code></pre>

<p>My default bitmap config is ARGB_8888. I tried each configuration in turn with the same results.</p>

<p>I tried using the Canvas.drawCircle() method to draw a circle at the 550px mark and it drew a circle fine, but the NinePatch still clipped.</p>

<p>I tried using a NinePatchDrawable instead of a NinePatch just for kicks--no difference.</p>

<p>The same problem continued to happen even with different nine patch images.</p>

<p>Finally, I thought that maybe it had to do with the Canvas having a clipping region set. So I traced Canvas' clip region just before the NinePatch is drawn:</p>

<p>Direct Traceview output from mCanvas.getClipBounds():</p>

<pre><code>05-16 01:59:47.439: mCanvas.getClipBounds(): Rect(0, 0 - 1024, 128)
</code></pre>

<p>The clip rectangle seemed to be fully encompassing my Bitmap. But just for fun, I decided to try adding this line directly before the NinePatch is drawn:</p>

<pre><code>mCanvas.clipRect(new Rect(0,0,1024,128));
</code></pre>

<p>And it worked! The NinePatch now draws beyond the 550px mark no problem.</p>

<p>Now, after this lengthy explanation, <strong>my question is this</strong>:</p>

<p>Why must I explicitly set the Canvas' clip rectangle? Am I missing something entirely or is this some sort of bug?</p>

<p>Thank you.</p>
