hi, i'm trying to draw bitmap in canvas.
the bitmap is used to draw text and background using canvas (named
canvasBitmap)
but the text or background that are drown to bitmap is not displayed,
as if it's out of bounds.
i have to translate the canvasBitmap at some points to make it draw at
right position.
The problem is i don't know how many pixel i should translate to.

here's the code example:

public OnDraw(Canvas c){

  Paint mBackgroundPaint = new Paint();
  mBackgroundPaint.setColor(Color.RED);

  String mText = "Testing";

  Paint mFontPaint = new Paint();
  mFontPaint.setColor(Color.WHITE);

  //setting rect
  Rect mBackgroundRect = new Rect();
  mFontPaint.getTextBounds(mText, 0, mText.length(), mBackgroundRect);

  //the bitmap to be drawn a text and backgroundRect
  Bitmap mBitmap = Bitmap.createBitmap(mBackgroundRect.width(),
                                mBackgroundRect.height(), 
Bitmap.Config.ARGB_8888);
  Canvas mCanvasBitmap = new Canvas(mBitmap);

  //draw text and background to bitmap
  mCanvasBitmap.drawColor(Color.CYAN);
  mCanvasBitmap.drawRect(mBackgroundRect, mBackgroundPaint);
  mCanvasBitmap.drawText(mText, 0, 0, mFontPaint);

  //draw bitmap to canvas
  c.drawBitmap(mBitmap, 0, 0, null);
}

this will only drawn Cyan color, the text and red background is not
displayed
i have to translate for example :
mCanvasBitmap.translate(0, mBackgroundRect.height())

to make it displayed (but not 100% correctly position)
please help >.<
thx

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to