1

在位图上绘制文本时,我想将文本旋转 180 度。位图本身也可以旋转,因为除了文本之外没有其他任何内容。我不清楚我应该在下面的代码中使用什么来旋转文本:ImageView、canvas、paint、bitmap???

  ImageView ivImage = (ImageView)findViewById(R.id.ivImage);

  DisplayMetrics metrics = getResources().getDisplayMetrics();
  int width = metrics.widthPixels;
  int height = metrics.heightPixels;

  Bitmap.Config conf = Bitmap.Config.ARGB_8888;
  Bitmap bitmap = Bitmap.createBitmap(width, height, conf);

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  paint.setColor(Color.RED);
  paint.setTextSize((int) (200 * 1));

  // draw text to the Canvas center
  Rect bounds = new Rect();
  paint.setTextAlign(Align.CENTER);

  String text = "HELP";

  paint.getTextBounds(text, 0, text.length(), bounds);
  int x = bitmap.getWidth() / 2; //  (bitmap.getWidth() - bounds.width())/2;
  int y = bitmap.getHeight() / 2; // (bitmap.getHeight() + bounds.height())/2; 

  canvas.drawText(text, x * 1, y * 1, paint);

  ivImage.setImageBitmap(bitmap);
4

1 回答 1

4

我希望这会有所帮助。这就是我在创建时钟时所做的

// Save canvas in current state
canvas.save();

// Rotate canvas around center and draw
canvas.rotate(degrees, canvasWidth/2, canvasHeigth/2);
canvas.drawText(text, x, y, paint)

// Restore canvas, rotates it back to original
canvas.restore();
于 2013-07-31T08:04:11.897 回答