Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Create image from Data (trivial)

Author
Message
Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 2nd Mar 2008 18:12
Very simple but handy li'l function to read in RGB triplets from data statements, and make an X*Y image from them, via a memblock.

I'm sure this has been done a billion times, since it's so handy for making medialess programs.



Changes you might want to make:
1) I write the fourth byte, alpha transparency, as the constant "255", meaning "completely opaque". You might want to read it in from a data statement instead, so you can make images with transparent areas.

2) I read from a data statement. You might want to read from a file or array or memblock or the screen or some other data source, instead.

3) I use IanM's "find free memblock()" and "find free image()" functions - if you do not want to use these, just give them an id, possibly passed as an optional parameter, or read from the data statement. In that case you might also want to do something like "if image exist ImageID then delete image ImageID", or "...endfunction 0" or something.

4) There's no reason the header of the image couldn't be stored in the data statement too. In which case, of course, you needn't pass parameters to the function.

<a href="http://www.thudgame.com/mmo">Yet another programmer</a>
All my posts are Public Domain unless I say otherwise.
You may use all my code and ideas as you see fit.

Login to post a reply

Server time is: 2024-11-22 13:09:11
Your offset time is: 2024-11-22 13:09:11