How to rotate a Drawable with rectangle shape in Android?
<p>I´m using this code to rotate a drawable 45 degrees:</p>

<pre><code>public static Drawable rotateImage(Context ctx) {
      // load the origial Bitmap
      Bitmap BitmapOrg = BitmapFactory.decodeResource(ctx.getResources(),
              R.drawable.car);



      int width = BitmapOrg.getWidth();
      int height = BitmapOrg.getHeight();
      int newWidth = 90;
      int newHeight = newWidth * height / width;

      // calculate the scale
      float scaleWidth = ((float) newWidth) / width;
      float scaleHeight = ((float) newHeight) / height;

      // create a matrix for the manipulation
      Matrix matrix = new Matrix();
      // resize the Bitmap
      matrix.postScale(scaleWidth, scaleHeight);
      // if you want to rotate the Bitmap
      matrix.postRotate(-45);

      // recreate the new Bitmap
      Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0,
                                                 width, height, matrix, true);

      // make a Drawable from Bitmap to allow to set the Bitmap
      // to the ImageView, ImageButton or what ever
      return new BitmapDrawable(resizedBitmap);

    }
</code></pre>

<p>The problem is although I give it a newWidth, the size of the Drawable is still the same and the image rotated appears stretched. How can I rotate the drawable if it's a rectangle to get a good appearance of the rotated image?</p>
