Page 1 of 1

24bit BMP functions!!!

PostPosted: Sun Jun 08, 2008 3:31 am
by pyrometal
Hello everyone! I've been working of functions that can load, draw and alter uncompressed 24bit bitmap files onto a canvas. Note, the loader uses only the width and height bytes in the header and basically ignores the rest of the header. My functions can load, scale up, flip, rotate by n*90 degrees, add/subtract color, invert colors, and conver to greyscale any compatible bitmap it is fed. The drawing function treats black as a transparent color.

screenshot.PNG

BMP24 reader.zip
It has it uses!
(4.91 KiB) Downloaded 306 times


To use them properly, first use:

- load_bmp24("file_name"); The file MUST be in the same location as the program.

Then use these if you want:

- invert_bmp24(); to invert the image's colors. (reuse to undo change)
- greyscale_bmp24(); to convert the image to a greyscale. (Converts image data, you must reload if you want the original again)
- RGBadd_bmp24(red, green, blue); to add or subtract color from the image. (Converts image data, you must reload if you want the original again)

Then, when you are ready to draw:

-draw_bmp24(positionX, positionY, Scale factor(positive integers only), flip image value (positive is normal, negative flips), number of 90degCW rotations);

The current image limits are that it can't have an area larger than that given by 320*240 pixels. You may increase it by modifying my codes slightly. Using these for realtime anymation is strongly discouraged because it is very demanding on the CPU. I would use these for seldomly updated and stationary elements like healthbars (non animated), and other such things as menu graphics, since it avoids creating numerous actors for very simple things.

I hope this may prove helpful to some of you out there!

ttyl! --Pyro

Re: 24bit BMP functions!!!

PostPosted: Sun Jun 08, 2008 4:01 am
by Caaz Games
Hmm interesting, you say it treats black as transparent, but i thought bmp doesn't have like the ability to be transparent

Re: 24bit BMP functions!!!

PostPosted: Sun Jun 08, 2008 4:05 am
by pyrometal
lol, it doesn't, but the algorithm is made so it doesn't draw black pixels on the canvas.

Re: 24bit BMP functions!!!

PostPosted: Sun Jun 08, 2008 4:18 am
by Caaz Games
oh ok Image