创建相册;需要一种动态放置不同尺寸图像的算法
好的,在我的小相册应用程序中(在 Flash/AS3 中,但语言并不重要),每个页面都有一个 5x4 的照片网格。然而,有些照片我想突出显示,因此其中一些照片不会占据 1x1 空间,而是占据 2x2 空间。
因此,如果我有一个正在迭代的图像对象数组,以便按顺序填充页面......跟踪 a)页面何时填充以及 b)是否适合 2x2 照片的最佳方法是什么在网格上的给定点上?
例如,在本例中,已放置前四张照片(用 x 标记)。第五张照片是 2x2...它显然无法放入第一行 5 列。位置...有什么好的算法可以决定它需要放置在下一行,并且第 1x5 个位置为下一张 1x1 照片开放?
XXXXO OOOOO OOOOO OOOOO
OK, so in my little album app (in Flash/AS3, but language doesn't matter), each page has a 5x4 grid of photos. However, some photos I want to elevate in prominence, so instead of occupying a 1x1 space, some of them would occupy a 2x2 space.
So, if I have an array of image objects that I'm iterating, in order, to fill pages sequentially...what's the best way to keep track of a) when a page is filled and b) if a 2x2 photo will fit on given point on the grid?
For example, in this case, the first four photos (marked by x's) have been placed. The fifth photo is a 2x2...it obviously can't fit in the 1st row, 5 col. position...what's a good algorithm for deciding that it needs to be placed in the next row, and that the 1x5th position is open for the next 1x1 photo?
XXXXO OOOOO OOOOO OOOOO
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果可能的话,首先放置大图像可能会更容易,因为这样您就可以用小图像填充所有剩余空间。
因此,如果您要从列表中提取这些图片,请向前跳转,直到找到一张大图片(或两张或三张,无论您想要多少张),然后放置它们。然后,跳回到开始的位置并填充未使用的图像(显然,跳过大图像)。要跟踪是否已全部填满,您可以保留一个计数器,对于小图像计数为 1,对于较大图像计数为 4,直到达到 20。
It would probably be easier, if possible, to place the large images first, because then you can fill all remaining space with little ones.
So if you are pulling these pictures from a list, jump ahead in it until you find a large one (or two or three, however many you want), and place those. Then, jump back to where you started and fill with the unused images (skipping the large ones, obviously). To keep track if it is all filled, you can keep a counter that counts 1 for small images and 4 for the larger ones until it hits 20.