我已尝试过此处建议的解决方案Android: How to overlay-a-bitmap/draw-over a bitmap?。我似乎工作,但我得到了一个稍微迷失方向的图像。
我已将编辑图标设置为在画布上的开始和停止绘图之间切换。当用户停止绘图时,我在imageView上检索画布位图和imageView以及覆盖画布位图。 从截图中可以看出,imageView是笔记本电脑图像,画布位图是我画的向上箭头。 这是我的叠加功能。
private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, new Matrix(), null);
return bmOverlay;
}
我是android的新手,并希望在这方面提供一些帮助。 谢谢!
答案 0 :(得分:3)
我认为你可以使用这样的东西来实现你想要的东西:
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
Canvas result = new Canvas(underlayBitmap);
result.drawBitmap(overlayBitmap, left, top, paint);
您可以将顶部和左侧放在要绘制叠加层的位置。
希望这会有所帮助。
答案 1 :(得分:1)
最简单的方法没有深入了解图形库是使用 FrameLayout ,使用此布局,您可以将一个视图放在另一个视图上方,因为它们是添加到布局中,例如:
<FrameLayout>
<ImageView android:id="@+id/imageView1" />
<ImageView android:id="@+id/imageView2" />
</FrameLayout>
在上面的示例中,imageView2将与imageView1重叠,这是迄今为止将一个图像与另一个图像重叠的最快方法。这种方法允许将View的任何后代放在另一个上面。