c++cimagebitmapimage-extraction

Extracting the "n"th image out of a bmp (or other image type)


I have a bmp image that's comprised of 13 images, and each image is exactly 17x17. Aside from breaking this image down through gimp into 13 different images, what is a good way to 'extract' the nth image from this list (into a char array, preferably) so that I may then use it? I've tried advancing the pointer forward by n*17*17 pixels, and aside from the fact that it ignores the header, thought this should work - unfortunately, it doesn't.

Suggestions?

Note that I've tagged this as C and C++ because I'm happy to see/hear of a solution in either language.


Solution

  • Perhaps use existing tools for tile cropping

    convert paged.gif  +gravity -crop 32x32  tiles_%d.gif
    

    Imagemagick comes with an API that is usable from many language, including C, C++, php, perl, etc etc The relevant function would seem to be

    CropImageToTiles