Home » C++ ProgrammingRSS


I have an exercise that has the following structure:

You given a folder. In a folder (and subfolders) there are a lot of
textures of different sizes and format (png, jpg). Your task is to
write a standalone application, which may pack them to the set of
square textures (each texture has to have power of 2 dimensions, i.e.
256x256, 512x512. 512x512 is optimal). Should be look like this:

I have no idea where to start from.

So anyone can give me some idea how to start?

I have read some articles about bin packing like

"Algorithms for  Two-Dimensional Bin Packing and Assignment Problems" by  Andrea Lodi

but I don't know how to implement it in c++.

I am not looking for a source code. I just need some guidance.

Thank you.



4 Answers Found


Answer 1

If you can use MFC you could use CBitmap and CImage to do a lot of this work (using GDI+).  If you are using C++/CLI with .NET you could use an .NET Image object to get a lot of the functionality as well.



Answer 2

Really this isn't that hard. The theory is to put them into one image and then use a function like GDI BitBlt or GDI+ Bitmap::Clone to copy out only what you need.

The important part is to realise that they don't need to copy the entire image at once, you can select parts of it. So if your image is a 10x10 image and in the source it is at coordinates (20, 10), then the call to BitBlt would probably be something like

BitBlt(hDst, 0, 0, 10, 10, hSrc, 20, 10, SRCCOPY);

assuming you are copying it to a location for the image on its own.

To make this work though you need to keep an index or keep the images at a regular size. So just a regular table (array of structures, maybe using vector) will be enough to store it. This table can just simply store the relevant information for the image.

Well, just read the GDI+ or GDI documentation. You should prefer GDI+ over GDI because of complexity. Once you know the library it should be pretty easy to figure out what to do.


Answer 3

Thank you for your answer.

I study now GDIi+ and I hope that I find what I need.

But trying to apply what I've seen there I have a problem.

I try to draw a line and I receive the following error:

Cannot open include file: 'stdafx.h': No such file or directory

And I don't know how to handle with it.


Answer 4

I was looking at the GDI+ classes and I don't think that I find there what I need.

As I thought it I need a container or a vector that has a dynamic dimension where to store the images and the an algorithm that is gonna arrange them

in order that no space be wasted.

I just cannot figure it out how to do this with the Bitmap::Clone method. 

Search for  exercise

<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter