title: Android rotating bitmap around center point with cropping the corners
body: <h2>Introduction</h2>
  
  <p>Hello everyone!</p>
  
  <p>I'm making an app that will rotate a bitmap that contains the map of my university based on compass changes. </p>
  
  <p>I have a squareish pictucre of my university and nearby area, on my phone it's a bit flattened:</p>
  
  <p><img src="https://i.stack.imgur.com/J7fV5.jpg" alt="enter image description here"></p>
  
  <p>Now i only need to display the campus area, i achieved that by drawing a Rectangle part of that bitmap on my custom View's canvas: </p>
  
  <p><img src="https://i.stack.imgur.com/94fgj.jpg" alt="enter image description here"></p>
  
  <h2>The Problem</h2>
  
  <p>My issue is that i'm unable to achieve rotating the bitmap around the center point. </p>
  
  <p>Right now rotation by 30 degrees looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/5DpaC.jpg" alt="enter image description here"></p>
  
  <p>and it doesn't do it's job at all, the campus disappears from the smaller rectangle.</p>
  
  <p>I wan't the image to be rotated around it's center and i want the corners of the image to go off the canvas, so the campus stays in the same place and rotates nicely.</p>
  
  <h2>Current approach</h2>
  
  <p>To display the map i have custom View with overriden onDraw method.</p>
  
  <pre><code>@Override
  protected void onDraw(Canvas canvas) {
      Rect rekt = new Rect();
      Rect tyrRekt = new Rect();
  
      super.onDraw(canvas);
  
      tyrRekt.set(0, 0, canvas.getWidth(), canvas.getHeight());
      rekt.set(350, 370, 1520, 900);
  
      canvas.drawBitmap(bitmap, rekt, tyrRekt, null);
  }
  </code></pre>
  
  <p>and the bitmap is rotated in AsyncTask to save some memory, RotateTaskParams is an object with oryginal bitmap and degrees:</p>
  
  <pre><code>@Override
  protected Bitmap doInBackground(RotateTaskParams... params) {
      Matrix matrix = new Matrix();
      matrix.postRotate(params[0].deg);
      rotateBitmap = new WeakReference&lt;Bitmap&gt;(Bitmap.createBitmap(params[0].bmp, 0, 0 ,params[0].bmp.getWidth(), params[0].bmp.getHeight(), matrix, true ));
      return rotateBitmap.get();
  }
  </code></pre>
  
  <h2>Things I've tried</h2>
  
  <p>I was searching for a lot, read tons of simliar questions here, and tried a lot of answers.
  What didn't work out for me (maybe i did something wrong)</p>
  
  <ul>
  <li>postTranslating matrix (center to the 0,0)</li>
  <li>rotating canvas</li>
  <li><p>postRotate around center of the bitmap</p>
  
  <p>matrix.postTranslate(params[0].deg, params[0].bmp.getWidth()/2 , params[0].bmp.getHeight()/2);</p></li>
  </ul>
  
  <p>the params[0].bmp is always a oryginal image.</p>
  
  <p><strong>Thanks in advance!</strong></p>