创建相册;需要一种动态放置不同尺寸图像的算法

发布于 2024-08-12 06:24:14 字数 350 浏览 6 评论 0原文

好的,在我的小相册应用程序中(在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法少女 2024-08-19 06:24:14

如果可能的话,首先放置大图像可能会更容易,因为这样您就可以用小图像填充所有剩余空间。

因此,如果您要从列表中提取这些图片,请向前跳转,直到找到一张大图片(或两张或三张,无论您想要多少张),然后放置它们。然后,跳回到开始的位置并填充未使用的图像(显然,跳过大图像)。要跟踪是否已全部填满,您可以保留一个计数器,对于小图像计数为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文