Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 在一个纹理中绘制多个位图_Algorithm_Actionscript 3_Flash - Fatal编程技术网

Algorithm 在一个纹理中绘制多个位图

Algorithm 在一个纹理中绘制多个位图,algorithm,actionscript-3,flash,Algorithm,Actionscript 3,Flash,我有一系列的图片,每个都是128*128。照片的数量是36张。 我想把它们放在一张图片中,这样它们就可以画成这样: public static const SIZE : int 1024; public var img1 : Bitmap; public var img2 : Bitmap; var bmp:BitmapData=new BitmapData(SIZE,SIZE,false,0); //Draw img1 at 0,0 bmp.draw(img1); //Draw img

我有一系列的图片,每个都是128*128。照片的数量是36张。 我想把它们放在一张图片中,这样它们就可以画成这样:

public static const SIZE : int 1024;
public var img1 : Bitmap;
public var img2 : Bitmap;

var bmp:BitmapData=new BitmapData(SIZE,SIZE,false,0);

//Draw img1 at 0,0
bmp.draw(img1); 

//Draw img2 at 512,0
bmp.draw(img2, new Matrix(1,0,0,1, SIZE/2, 0)); 

//Draw img1 at 512,512
bmp.draw(img1, new Matrix(1,0,0,1, SIZE/2, SIZE/2)); 

//Draw img1 at 0,512
bmp.draw(img2, new Matrix(1,0,0,1, 0, SIZE/2));  

我的问题是我想提出一种算法来放置图像,而不考虑数字,这样我就不会用静态代码创建图像。。一个伪代码,如果您无法使用AS3获取它,它会有所帮助。

一般的想法是将较小的图像复制到较大的图像,从顶部开始向右移动,当顶部行满时向下移动到下一行

因此,假设您有一个要填充的大图像,以及一个要放入其中的小图像数组,该算法如下所示:

xpos = 0
ypos = 0
for i = 0 to number_of_small_images-1
    draw SmallImages[i] on BigImage at position (xpos, ypos)
    xpos += small_image_width
    if (xpos >= big_image_width)
        xpos = 0
        ypos = ypos + small_image_height

这是基本的想法。你必须用你正在使用的任何编程语言来充实代码。

一般的想法是将较小的图像复制到较大的图像上,从顶部开始向右移动,当最上面的一行已满时向下移动到下一行

var images:Vector.<Bitmap> = new Vector.<Bitmap>();
images[0] = bmp1;
images[1] = bmp2;
// etc...

var i:int = 0;
var l:int = images.length;
var maxWidth :int = 0;
var totalHeight:int = 0;
var matrix:Matrix = new Matrix();
var render:Bitmap; // your final render


// find how tall will be the picture:
for ( i = 0; i < l; i++ ) {
    maxWidth = Math.max(maxWidth , images[i].width); // find the widest image
    totalHeight += images[i].height; // find the total height of your image
}

// create the render container based on the data we just found out:
render = new Bitmap( new BitmapData( maxWidth , totalHeight, true, 0xff00ff ) );

// draw!
for ( i = 0; i < l; i++ ) {
    render.bitmapData.daw(images[i], mat);
    matrix.translate(0, images[i].height);
}
因此,假设您有一个要填充的大图像,以及一个要放入其中的小图像数组,该算法如下所示:

xpos = 0
ypos = 0
for i = 0 to number_of_small_images-1
    draw SmallImages[i] on BigImage at position (xpos, ypos)
    xpos += small_image_width
    if (xpos >= big_image_width)
        xpos = 0
        ypos = ypos + small_image_height
这是基本的想法。您必须用您正在使用的任何编程语言充实代码。

var images:Vector.=新向量();
var images:Vector.<Bitmap> = new Vector.<Bitmap>();
images[0] = bmp1;
images[1] = bmp2;
// etc...

var i:int = 0;
var l:int = images.length;
var maxWidth :int = 0;
var totalHeight:int = 0;
var matrix:Matrix = new Matrix();
var render:Bitmap; // your final render


// find how tall will be the picture:
for ( i = 0; i < l; i++ ) {
    maxWidth = Math.max(maxWidth , images[i].width); // find the widest image
    totalHeight += images[i].height; // find the total height of your image
}

// create the render container based on the data we just found out:
render = new Bitmap( new BitmapData( maxWidth , totalHeight, true, 0xff00ff ) );

// draw!
for ( i = 0; i < l; i++ ) {
    render.bitmapData.daw(images[i], mat);
    matrix.translate(0, images[i].height);
}
图像[0]=bmp1; 图像[1]=bmp2; //等等。。。 变量i:int=0; var l:int=images.length; var maxWidth:int=0; var totalHeight:int=0; var矩阵:矩阵=新矩阵(); var render:Bitmap;//您的最终渲染 //找出图片的高度: 对于(i=0;i
我无法测试它,但它应该可以工作,或者至少让你走上正确的方向。让我知道

var图像:向量新向量();
图像[0]=bmp1;
图像[1]=bmp2;
//等等。。。
变量i:int=0;
var l:int=images.length;
var maxWidth:int=0;
var totalHeight:int=0;
var矩阵:矩阵=新矩阵();
var render:Bitmap;//您的最终渲染
//找出图片的高度:
对于(i=0;i

我无法测试它,但它应该可以工作,或者至少让你走上正确的方向。让我知道

我想让它们一个接一个地倒下,就像一卷照片。倒下?通常会提供一些反馈。你觉得这个答案有什么特别的错误吗?@JimMischel我是对你的回答投了反对票的人。我认为这对他的问题没有多大帮助,我认为我提供了一个更清楚的解释。无意冒犯,但这是一个AS3问题。我希望他们一个接一个地倒下,就像一卷照片。倒下?通常会提供一些反馈。你觉得这个答案有什么特别的错误吗?@JimMischel我是对你的回答投了反对票的人。我认为这对他的问题没有多大帮助,我认为我提供了一个更清楚的解释。无意冒犯,但这是一个AS3问题。谢谢,它起作用了,但它们彼此水平向下,我如何使它们垂直?。我喜欢总高度累积的想法:)。最终图像应该是2的幂,宽度和高度,所以我将最终高度和宽度修改为2的幂。在将位图绘制到大纹理之前,我如何将其旋转90度?您需要仔细观察才能更好地理解矩阵如何改变位置。查看矩阵。旋转()。另一种方法是创建一个常规的显示精灵,添加尽可能多的图像,旋转并放置图像,然后绘制精灵而不是图像。请详细说明精灵解决方案?将所有图像作为子对象添加到显示对象(精灵),就像将其放置在舞台上一样。然后立刻画精灵。bitmapData.draw(spriteContainer);谢谢,它起作用了,但是它们是水平向下的,我怎样才能使它们垂直呢?。我喜欢总高度累积的想法:)。最终图像应该是2的幂,宽度和高度,所以我将最终高度和宽度修改为2的幂。在将位图绘制到大纹理之前,我如何将其旋转90度?您需要仔细观察才能更好地理解矩阵如何改变位置。查看矩阵。旋转()。另一种方法是创建一个常规的显示精灵,添加尽可能多的图像,旋转并放置图像,然后绘制精灵而不是图像。请详细说明精灵解决方案?将所有图像作为子对象添加到显示对象(精灵),就像将其放置在舞台上一样。然后立刻画精灵。bitmapData.draw(spriteContainer);