не удалось нарисовать текст поверх растрового изображения

Я хочу вывести точку и текст поверх изображения. Я пробовал несколько руководств по наложению растрового изображения, но, похоже, это не работает. Вот код, который отображает фоновое изображение.

mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.roomplan);
mIV = (ImageView)findViewById(R.id.ImageView01);
mIV.setImageBitmap(mBitmap); 
mIV.invalidate();

btnDraw = (Button)findViewById(R.id.Button01);
btnDraw.setOnClickListener(this);

Затем в OnClickListener я определяю другое растровое изображение и рисую точку и текст.

Bitmap bmOverlay = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), 
    Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bmOverlay);
Paint paint = new Paint();
paint.setColor(Color.CYAN);
paint.setTextSize(20);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
canvas.drawText("You are here", 100, 100, paint);
canvas.drawPoint(30.0f, 50.0f, paint);
canvas.drawBitmap(bmOverlay, 0, 0, null);

Ничего не отображается поверх фонового изображения, даже когда я удаляю изображение. Подскажите, пожалуйста?

Обновление: Рабочий код

// get a reference to the background image
mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.raumplan_isst);

mIV = (ImageView)findViewById(R.id.ImageView01);

// create a mutable bitmap with the same size as the background image
Bitmap bmOverlay = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), 
    Bitmap.Config.ARGB_4444);
// create a canvas on which to draw
canvas = new Canvas(bmOverlay);

Paint paint = new Paint();
paint.setColor(Color.CYAN);
paint.setTextSize(20);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);

// if the background image is defined in main.xml, omit this line
canvas.drawBitmap(mBitmap, 0, 0, null);
// draw the text and the point
canvas.drawPoint(fKoordX, fKoordY, paint);
canvas.drawText("You are here", fKoordX+3, fKoordY+3, paint);

// set the bitmap into the ImageView
mIV.setImageBitmap(bmOverlay);
7
задан springrolls 15 February 2011 в 14:52
поделиться