2

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.

Ben Stott
  • 2,218
  • 17
  • 23
  • Have you tried using OpenCv for this? I'm sure it has functionality that can help you. – Tony The Lion Apr 12 '11 at 09:55
  • I'm trying to find a way to do this without introducing any dependencies on any external libraries, really. Whilst I'm sure this is reinventing the wheel, I'd be happy to be suggested a function and to then view the code used in it – Ben Stott Apr 12 '11 at 09:56
  • What didn't "work" about your approach? And we need to know how you've laid out the image data. – Lightness Races in Orbit Apr 12 '11 at 09:59
  • The image seems to be displaying garbage data. As for how I've laid it out, it's in a standard char* array, ARGB format (though I don't think BMP can have alpha channels?). – Ben Stott Apr 12 '11 at 10:08
  • There is a very large number of possible layouts for the image, it's not clear exactly how your image looks. Is it a "strip" of tiles, each sharing one border with the next one? If so, is that strip horizontal or vertical? It could also be any number of rectangular layouts, with some wasted space. – unwind Apr 12 '11 at 10:55
  • It's a strip of tiles, and each is adjacent to the next image (i have one horizontal and one vertical image), though the borders are adjacent, too. There is no wasted space, either. – Ben Stott Apr 12 '11 at 11:01

1 Answers1

1

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

sehe
  • 374,641
  • 47
  • 450
  • 633
  • +1 for the tile cropping suggestion. I'd still like a way to extract my image internally from inside C/++ without an extra API, but nice suggestion. :) – Ben Stott Apr 12 '11 at 10:34
  • Marked as answer - this did solve my question, so it's probably worthy to be noted for others. – Ben Stott Apr 12 '11 at 12:36