Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ca_priest

converting a 256 color image file into a simple array

This topic is 5825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can i convert an image file into a simple array containing the numbers corresponding to the color of each particular pixel, assuming the image uses the same "default" palette. The type of image file doesn''t really matter to me, whichever i can do this with is the one ill use, so .bmp, .pcx or whatever else is fine. For example...if i create an array: image[32][32] and i fill each variable inside that array with the number 2, then i cycle through the array plotting pixels with the color parameter being whatever the value inside the array is, in this case always 2, which is a bright green color. So basically what i want to do is take image files, all made with the same basic default 256 color palette, and convert them simply into a string of numbers, where each number corresponds to the color of a pixel. I want to leave out headers, palettes, everything...except the pixel colors. Any help with this is greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Tell us more... What OS/API are you using? Will be a lot simpler to explain a method more directly with code.

Otherwise all you need to do is just load an image and then just let ever element in the array point to a pixel on the bitmap.

Here''s some pseudo code

int array_for_pixels[32][32];
char *pointer_to_pixels = (char *)bitmap.raw_pixel_data_pointer;

for(int y = 0; y < 32; y++)
for(int x = 0; x < 32; x++)
array_for_pixels[x][y] = pointer_to_pixels[x + y * bitmap.screen_pitch];

Try that, but tell which API and OS you are using.

-----------------------------
Final Frontier Trader
Well im using regular C, compiled on djgpp. Im using the general idea of the code you gave above...im going to see if i can get it to work, i assume i can try this with a windows bitmap? Ill post whether or not it worked. Thanks for the reply and the help.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!