car*_*erz 2 android 2d surfaceview map-edit android-canvas
我试图将我的所有小图像,如草,水和沥青等,放到一个位图中.
我有一个像这样的数组:
public int Array[]={3, 1, 3, 3, 1, 1, 3, 3, 3, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1 ,1 ,1, 1, 1 ,1 ,1
,7 ,7 ,7, 7, 7 ,7, 7 ,7 ,7, 7
,7 ,7 ,7 ,7, 7 ,7, 7 ,7 ,7 ,7
,7 ,7 ,7 ,7, 7, 7, 7, 7 ,7 ,7
,7 ,7 ,7 ,7, 7, 7 ,7 ,7 ,7 ,7
,7 ,7 ,7 ,7, 7, 7, 7 ,7 ,7, 7
,6, 6, 6, 6, 6 ,6 ,6, 6, 6 ,6
,6, 6, 6 ,6, 6, 6 ,6, 6 ,6 ,6 };
Run Code Online (Sandbox Code Playgroud)
所以基本上这是10*10每个数字都是图像(数字).png的占位符
但是我如何将它们合并在一起呢?
//西蒙
好的,所以下面的代码片段应该并排组合两个图像.我不想推断10,但我相信你会自己弄清楚for循环.
public Bitmap combineImages(Bitmap c, Bitmap s) {
Bitmap cs = null;
int width, height = 0;
if(c.getWidth() > s.getWidth()) {
width = c.getWidth() + s.getWidth(;
height = c.getHeight());
} else {
width = s.getWidth() + s.getWidth();
height = c.getHeight();
}
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, c.getWidth(), 0f, null);
//notice that drawing in the canvas will automagically draw to the bitmap
//as well
return cs;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |