我可以将许多位图保存到一张位图吗? (2d)
我有一个二维数组,其中包含用于二维地图显示的坐标。 这些被绘制到画布上。 每当我想在画布上改变一些东西时,绘制这些都是非常沉重的, 所以我在想是否可以不通过 2d 数组进行 For 循环,如果我可以保存第一次执行的结果,并在每次更改其他内容然后 2d 地图时从保存中恢复。
似乎canvas.save()和canvas.restore()只能被同等次数地调用,所以我不能存储第一个输出,然后恢复它123次。
我在想是否可以通过其他方式保存画布,也许可以将第一个结果保存到 bipmap 中?
我知道我不能“调整”/“编辑”任何已经绘制到画布上的东西, 地图永远不会改变。
I have a 2-d array with cordinates for a 2d-map display.
These are drawed to a canvas.
Its very heavy to draw these everytime i want to change something on my canvas,
so i was thinking if it is possible to instead of For-looping thru the 2d-array, if i could save the result of the first time i do it, and restore from the save everytime i change something else then the 2d-map.
seems as canvas.save() and canvas.restore() can only be called equally times, so i cant store the first output, and then restore it 123 times.
I was thinking if it was possible to save the canvas in some other way, maybe by saving the first result to a bipmap?
I know i cannot "tweak"/"edit" anything that allready is drawn to the canvas,
the map never changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我明白了。
我可以使用画布将包含大量图像的背景绘制到一张位图上,非常简单。
首先创建一个具有所需 int 高度和 int 宽度的空位图,这将是您将绘制所有图块的位图(小图像)。
位图背景 = Bitmap.createBitmap(宽度, 高度, Bitmap.Config.ARGB_4444);
(不确定语法 Bitmap.Config.ARGB_4444 ,使用工具提示)
然后用 new Canvas(bitmap) 创建一个画布,这将使画布写入位图。
画布画布新画布(背景);
现在您可以随心所欲地编写画布,所有内容都将存储在位图中以供以后使用。
Ok so i figured it out.
I can draw my background containing lots of images to one bitmap using canvas, its pretty simpel.
First create an empty bitmap with desired int height and int width, this will be the bitmap tht you will draw all your tiles to (small images).
Bitmap background = Bitmap.createBitmap(width, heigth, Bitmap.Config.ARGB_4444);
(Not sure about the syntax Bitmap.Config.ARGB_4444 , use tooltip)
Then create a canvas with new Canvas(bitmap), this will make the canvas write to the bitmap.
Canvas canvas new Canvas(background);
Now you can write the canvas as you please, all will be stored in the bitmap for later use.