Java: How to draw pictures on the smallest possible surface?

advertisements

Let's say I have 256 images with an average size of 70x150 (So, size if variable). And I have a Graphic-instance (Created from a BufferedImage with a given size) on which I want to draw the images. But I want to draw them at the lowest possible surface. So, not simply in a grid, but really puzzled in each other. But!: they may not overlap each other.

Maybe this something only a human brain can manage.
It is worth asking it, I think....

Thanks in advance,
Martijn

For example:

+------++------+
|      ||      |
| img1 || img2 |
|      |+------+
|      |+-----------------+
+------+|                 |
+---+   |                 |
| 3 |   |                 |
|   |   |    img 4        |
+---+   |                 |
        |                 |
        +-----------------+


This question has been asked before: What algorithm can be used for packing rectangles of different sizes into the smallest rectangle possible in a fairly optimal way?

A good survey, from a previous answer, is available at: http://www.csc.liv.ac.uk/~epa/surveyhtml.html