Resizing or Clipping after a rotation
<p>I have a 10x10 tablelayout with each cell containing an ImageView. I simulate the moving across this gamegrid by updating the pictures in each grid on a move event. I also rotate the image to align the image with the direction of travel. My problem is that as the image rotates it causes my cell rows and columns to expand to fit the rotated image. </p>

<p>What I would like is to have the image cropped to remain within the dimensions of the table row and columns. If that isnt possible then I would like to scale the image to remain within the dimensions of the original table cell.</p>

<p>Another potential issue is that the images are getting scaled initially to fit into the cells (this is done automatically as the table expands to fill the screen). I don't want to change that behavior. I just want to trim off the corners of the image as they pass the original boundaries of the table cell when they are rotated.</p>

<p>My rotation code is below:</p>

<pre><code>Matrix matrix = new Matrix();
matrix.postRotate((float) (360 - sector.getShip().getHeading()));
Bitmap bMap = BitmapFactory.decodeResource(image.getContext().getResources(), getShip().getGridSymbol());
image.setImageBitmap(Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), matrix, true));
image.setImageResource(sector.getShip().gridParams.default);
</code></pre>

<p>My table configuration is below:</p>

<pre><code>&lt;TableLayout android:id="@+id/quadrantGrid" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignWithParentIfMissing="true" android:stretchColumns="*" android:background="#000000"&gt;
...
&lt;TableRow&gt;
    &lt;TextView android:text="1" android:background="#404040" android:gravity="center"&gt;&lt;/TextView&gt;
    &lt;ImageView android:id="@+id/grid00"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid01"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid02"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid03"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid04"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid05"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid06"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid07"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid08"&gt;&lt;/ImageView&gt;
    &lt;ImageView android:id="@+id/grid09"&gt;&lt;/ImageView&gt;
&lt;/TableRow&gt;
...
</code></pre>

<p><strong>UPDATE:</strong>
I found a solution, though I'm not sure its the most efficient solution.</p>

<p>All my images are 25x25. And so the OS figures how to scale those images to fit into the cell. The solution just performs two operations. First it rotates, and then it creates a smaller image from the rotated image. (note: When I created my image I made sure the important parts of the image would be contained within a circle with a diameter of the width of the image to allow for this type of cropping).</p>

<p>My code is below. I would prefer to perform both operations within one method, but Im not sure how so I just break it down into two steps.</p>

<pre><code>Matrix matrix = new Matrix();
matrix.postRotate((float) (360 - sector.getShip().getHeading()));
Bitmap bMap = BitmapFactory.decodeResource(image.getContext().getResources(), getShip().getGridSymbol());
bMap = Bitmap.createBitmap(bMap, 0, 0, 25, 25, matrix, true);
int x = (bMap.getWidth() - 25) / 2;
int y = (bMap.getHeight() - 25) / 2;
image.setImageBitmap(Bitmap.createBitmap(bMap, x, y, 25, 25));
</code></pre>
