android:如何将位图数组合并到一个位图中?
我正在尝试在 Android 上制作一个用于平铺的地图加载器.. 到目前为止,我可以解析 tmx 文件,获取所有图块数据,并将它们放入二维数组中,如下所示: Bitmaptiles[x][y] ... 它可以工作,我现在可以在android上渲染平铺地图,但只能通过tiles[][]数组进行交互,如下所示..
如何将位图数组的内容合并到一个位图中?
这是我的渲染方法:
//here's what i have:
for (int x = 0; x < MapLoader.width; x++) {
for (int y = 0; y < MapLoader.height; y++) {
g.drawBitmap( picSource[x][y], posX, posY, BitmapPaint);
}
}
//and here's what i'd like to have:
g.drawBitmap( picDest, posX, posY, BitmapPaint);
我想迭代 picSource[x][y] 获取所有 位图并将它们全部放入 picDest 中。所以我可以获得 1 个大图片,代表我已加载并从平铺 tmx 文件构建的地图..
(请注意,picSource[][] 数组中包含的位图不位于相同位置.. 没有位图叠加在任何其他位图之上,它们只是显示在网格中 例如,每个都是 4x3 网格中的 32x32 位图。 每个网格上都有自己的位置..)
感谢您的帮助
i'm trying to make a map loader for tiled, on android..
so far i could parse the tmx file, grab all the tile data, and put them in a 2dimensional array, like this: Bitmap tiles[x][y] ...
it works and i can render tiled maps on android now, but only by interating through that tiles[][] array, like shown below..
how can i merge together in one single bitmap the content of a bitmap array ?
here's my render method:
//here's what i have:
for (int x = 0; x < MapLoader.width; x++) {
for (int y = 0; y < MapLoader.height; y++) {
g.drawBitmap( picSource[x][y], posX, posY, BitmapPaint);
}
}
//and here's what i'd like to have:
g.drawBitmap( picDest, posX, posY, BitmapPaint);
i would like to itterate through picSource[x][y] grab all the
bitmaps and put them all in picDest. so i can get 1 single big pic, representing the map i've loaded and constructed from tiled tmx file..
( note that no bitmap contained in the picSource[][] array is located a the same position ..
there's no bitmap on top of any other, they're just displayed in a grid
each is a 32x32 bitmap in a 4x3 grid for example..
each its own spot on the grid .. )
thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我制作了仅使用位图库即可工作的以下版本。它适用于一维数组,但更改它以处理矩阵将是微不足道的。
I made the following version that would work using only the Bitmap library. It works with one-dimensional arrays but change it for working with matrices would be trivial.
如果其他人想知道,我将发布我是如何做到的:
MapLoader 类用每个图块的 int 值填充数组“block[x][y]”。
我们循环遍历该数组,查找 pos 处的所有图块: x,y 的值为 169。
当找到一个时,相应的位图,取自
瓦片
(总是同一个......在图块表上的相同位置:0,0,16,16,它是用于碰撞的 16x16 红色图块),
被绘制到数组循环所在的相同 pos.x,y 处的临时位图中。
当退出循环时,collisionPicDest位图已经构建完毕,
由许多较小的部件混合在一起形成最后一张照片。
In case someone else is wondering, i'm posting how i did it:
MapLoader class filled the array "block[x][y] with an int value for each tile.
we loop through that array, looking for all tiles at pos:x,y with value 169.
when one is found, the corresponding bitmap, taken from the
tilesheet
(alway the same one..at same position on the tilesheet: 0,0,16,16 it's a 16x16 red tile used for collisions),
is drawn into a temporary bitmap at the same pos.x,y that the array loop is at.
when the loop is exited, collisionPicDest bitmap have been built,
out of lots of smaller parts blended together in 1 final pic.