Piece together several images into one big image

前端 未结 6 767
抹茶落季
抹茶落季 2021-01-18 09:34

I\'m trying to put several images together into one big image, and am looking for an algorithm which determines the placing most optimally. The images can\'t be rotated or r

6条回答
  •  余生分开走
    2021-01-18 09:49

    Optimal packing is hard, but there might be simplifications available to you depending on the details of your problem domain. A few ideas:

    1. If you can carve up your bitmaps into equally sized tiles, then packing is trivial. Then, on-demand, you'd reassemble the bitmaps from the tiles.

    2. Sort your images largest to smallest, then, for each image use a greedy-allocator to select the first available sub-rectangle that fits the image.

    3. Use a genetic algorithm. Start with several randomly-selected layouts. Score them based on how tightly they're packed. Mix solutions from the top scoring ones, and iterate until you get to an acceptable score.

提交回复
热议问题