我可以省下不少的位图到一个位图? (2d)的位图、省下

2023-09-04 05:24:14 作者:掰开心给你看要不

我有个的2-D阵列cordinates为一个二维地图显示。 这些drawed到画布上。 它非常重画这些每次我想改变我的画布上的东西, 所以我想,如果有可能,而不是为了套住通二维数组,如果我能救我第一次这样做的结果,并从保存每次我换别的东西那么二维地图恢复。

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.

似乎canvas.save()和canvas.restore()只能叫同样时间,所以我不能存储第一个输出,然后恢复123次。

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.

我在想,如果有可能保存在画布上一些其他的方式,也许是保存第一个结果到bipmap?

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.

推荐答案

好了,所以我理解了它。 我可以借鉴我的背景用帆布含有大量的图片到一个位图,它的pretty的simpel。

Ok so i figured it out. I can draw my background containing lots of images to one bitmap using canvas, its pretty simpel.

首先创建具有所需INT的高度和宽度INT一个空的位图,这将是位图THT你会得出所有的砖(小图)。

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.createBitmap(宽度,heigth,Bitmap.Config.ARGB_4444);

Bitmap background = Bitmap.createBitmap(width, heigth, Bitmap.Config.ARGB_4444);

(不知道语法Bitmap.Config.ARGB_4444,使用工具提示) 然后创建一个画布新的Canvas(位图),这将使画布写入位图。

(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.