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,paint);canvas.drawPoint(30.0f,50.0f,paint);canvas.drawBitmap(bmOverlay,null);
即使我删除图像,背景图像上也不会显示任何内容.有什么提示吗?
更新:工作代码
// get a reference to the background imagemBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.raumplan_isst);mIV = (ImageVIEw)findVIEwByID(R.ID.ImageVIEw01);// create a mutable bitmap with the same size as the background imageBitmap bmOverlay = Bitmap.createBitmap(mBitmap.getWIDth(),Bitmap.Config.ARGB_4444);// create a canvas on which to drawcanvas = 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 linecanvas.drawBitmap(mBitmap,null);// draw the text and the pointcanvas.drawPoint(fKoordX,fKoordY,paint);canvas.drawText("You are here",fKoordX+3,fKoordY+3,paint);// set the bitmap into the ImageVIEwmIV.setimageBitmap(bmOverlay);解决方法 你怎么用画布?在哪里使用? (发布更多代码……)
除了绘图顺序错误之外,您正在透支您的文本并使用位图指向.
编辑:
我有点迷失,因为我不知道你的哪些图像应该是背景,你已经看到了什么图像…所以我猜mBitmap(roomplan)是你的背景?然后将其添加到您的布局作为背景图像,并使用ImageVIEw绘制您的叠加层…
如果您的叠加层也需要背景图片,请尝试:
// overlay backgroundcanvas.drawBitmap(myBmp,paint);// draw the text and the pointcanvas.drawText("You are here",paint);
如果您的ImageVIEw应该将roomplan作为背景,请尝试:
// overlay backgroundcanvas.drawBitmap(mBitmap,paint);总结
以上是内存溢出为你收集整理的android – 在位图顶部绘制文本失败全部内容,希望文章能够帮你解决android – 在位图顶部绘制文本失败所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)