如何覆盖了位图在特定的XY位置另一个位图 [英] How to overlay bitmap over another bitmap at particular XY position
问题描述
我的工作,我已经用帆布和用户可以触摸一个位图叠加移动到另一个位图的一个项目。当用户presses保存按钮,然后这两个位图应该合并成为一个单一的位图。我已经做了所有的事情,现在合并两个位图在XY位置仍然存在。在我的研究,我发现以下code。
I am working on a project where I have used canvas and user can touch move one bitmap overlay to another bitmap. When user presses save button then both bitmaps should merge and become a single bitmap. I have done all things and now merging two bitmap at XY position remains. During my research I found following code.
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;
}
但在(0,0)位置,这code覆盖位图。我想在我指定的位置重叠位图。请提出一些解决方案。先谢谢了。
But this code overlay bitmap at (0,0) location. I want to overlay bitmap at my given location. Please suggest some solution. Thanks in advance.
推荐答案
低于code使用
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, x,y, null);
return bmOverlay;
}
其中x和y,你必须绘制覆盖位图的实际位置。
Where x and y are actual positions where you have to draw the overlay bitmap.
这篇关于如何覆盖了位图在特定的XY位置另一个位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!