title: Android - Rotated text on a large bitmap
body: <p>I have a picture (bitmap) and I want to draw some shapes and rotated
  text on it.</p>
  
  <p>This works fine as long as the picture doesn't get too large. However,
  when using a picture (2560 x 1920 pixels)taken with the build-in
  camera of my android 2.1 phone, the result is distorted.
  It looks like the rotation back, after drawing the rotated text, has
  not been completed. Also, the distortion point is not always the same,
  like it depends on the cpu usage.</p>
  
  <p>You can see some resulting pictures here: <br/>
  <a href="http://dl.dropbox.com/u/4751612/Result1.png" rel="nofollow">http://dl.dropbox.com/u/4751612/Result1.png</a> <br/>
  <a href="http://dl.dropbox.com/u/4751612/Result2.png" rel="nofollow">http://dl.dropbox.com/u/4751612/Result2.png</a></p>
  
  <p>The code is executed inside a AsyncTask. The strange this is that this code works fine in one Activity, but not in another. In both activities the AsyncTask is executed when a button is clicked.</p>
  
  <p>These are some excerpts of the code I'm using.</p>
  
  <pre><code>// Load the image from the MediaStore
  c = MediaStore.Images.Media.query(context.getContentResolver(),
  Uri.parse(drawing.fullImage), new String[] {MediaColumns.DATA});
  if (c != null &amp;&amp; c.moveToFirst()) {
         imageFilePath = c.getString(0);
         bitmap = ImageUtil.getBitmap(new File(imageFilePath), 10000);
  }
  c.close();
  
  // Create a canvas to draw on
  drawingBitmap = Bitmap.createBitmap(bitmap.getWidth(),
  bitmap.getHeight(), Bitmap.Config.ARGB_8888);
  canvas = new Canvas(drawingBitmap);
  
  // Draw image
  canvas.drawBitmap(bitmap, 0, 0,
  MeasureFactory.getMeasurePaint(context));
  
  // calculate text width
  rect = new Rect();
  paint.getTextBounds(text, 0, text.length(), rect);
  
  // Draw rotated text
  canvas.save();
  canvas.rotate(-angle, centerPoint.x, centerPoint.y);
  canvas.drawText(text, centerPoint.x-Math.abs(rect.exactCenterX()),
  Math.abs(centerPoint.y-rect.exactCenterY()), paint);
  canvas.restore();
  
  // Upload the bitmap to the Media Library
  Uri uri =
  getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
  values);
  OutputStream outStream = getContentResolver().openOutputStream(uri);
  drawingBitmap.compress(Bitmap.CompressFormat.JPEG, 90, outStream);
  outStream.flush();
  outStream.close();
  </code></pre>
  
  <p>Thanks in advance for any help.</p>