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.

DarkBASIC Discussion / Getting pixel color

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Mar 2008 17:48
Hey guys!

Is there a command "get pixel color"? What I`m trying to do, is load a bitmap, get all pixel colors in them stored in arrays, and save each pixel to a file with the the rgb() input. Then I can copy those numbers into DarkBasic and the code will generate the bitmap by itself.

Example:
Pixel color : red

stored values : r=255 : g=0 : b=0

DarkBasic will make the pixel:
create bitmap 1,size x,size y
ink rgb(r,g,b)
dot x,y

Is this possible, or is there another way to store a bitmap in the code?

Thanks, TheComet

Oooooops!!! I accidentally formated drive c.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Mar 2008 19:52
Quote: "Is there a command "get pixel color"?"


Yes - Point() - it's in the Basic2D section of the help files. RGBR(), RGBG() and RGBB() will then give you the RGB values.

Your biggest problem is going to be speed - or more precisely, the lack of it!

TDK_Man

Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 7th Mar 2008 19:53 Edited at: 11th Aug 2010 22:29
See,

ThisRGB=POint(Xpos,Ypos)

However in DB classic it's virtually useless (It's very very slow).

Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 7th Mar 2008 20:02
what about memblocks?

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Mar 2008 20:49
Quote: "what about memblocks?"


Oh no! Here we go again!

Meaning, my DBC isn`t enhanced and can not be enhanced or upgraded, because I bought it at a store as a CD.

And please don`t quote that and ask all sorts of questions how I could get around it, just view this thread : http://forum.thegamecreators.com/?m=forum_view&t=120711&b=10

Oooooops!!! I accidentally formated drive c.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Mar 2008 01:53
@TheComet
Are you trying to create DATA statements of the color information from a bitmap? Or are you just trying to store all the bytes of a bitmap file into an array, so you can later write the array back to a file and it will be that bitmap? If you want to store the entire bitmap inside your code as data statements then just read the bitmap in and write out each byte in a string as data statments. Maybe 20 to 40 values per line:

data 0,0,2,0,0,45,0,0 etc Then you can include the data statements in your program. All you'd have to do is read the data and write each byte back to a file, then load the file as a bitmap or image.

If you want just the color data, if your plan is to later do something like INK color,0 dot x,y you can read the color data from the bitmap file. It can be tricky because the bitmap starts with a 54 byte header then it's followed by color data. Depending on whether the bit depth is 8,16,24, or 32 bit, the color data may be padded. This means there are extra zeros at the end of each line across the bitmap. This is so the width of each line as it's stored falls neatly into a 4 byte divisible scanline.

You'll want to look up the bmp file format so you can see what the elements of the header are.

Basically the method for extracting the color data is:
1. get the file size
2. subtract 54 from the file size. This is the size of your color data so DIM array(this size)
3. calculate the padding (the extra zeros that will appear per xacross) subtract this from your bitmap width
4. open the file to read
5. read through the first 54 bytes
6. starting with byte 55, start reading the bytes of your colors until you reach the padding
7. skip the number of bytes for padding
8. start reading the next line of color
9. when file end is reached, close file

If you look through the DBC challenges, this is the method I used to create 3d matrix text. It's quite fast. Bascially, I take a line of text that the user types, each letter is saved as a bitmap then read back in and converted to a mini matrix by reading the color data.

Enjoy your day.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Mar 2008 02:41
@ Latch

Great tips! I was trying to create DATA statements with the color of the bitmap.

I noticed, the point() command only takes the colors from objects, but not sprite images. How do I get it to take color values from sprites?

Oooooops!!! I accidentally formated drive c.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Mar 2008 17:12 Edited at: 8th Mar 2008 17:12
Quote: "How do I get it to take color values from sprites?"


The sprites were made from images right?...

TDK_Man

Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 8th Mar 2008 23:44
Quote: "Oh no! Here we go again!

Meaning, my DBC isn`t enhanced and can not be enhanced or upgraded, because I bought it at a store as a CD.

And please don`t quote that and ask all sorts of questions how I could get around it, just view this thread :"

The 1.2 download is fixed now, you know

Lee Bamber - Blame Beer
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Mar 2008 18:12
It is? Great!! (Downloading now)

Oooooops!!! I accidentally formated drive c.

Login to post a reply

Server time is: 2025-06-04 03:26:34
Your offset time is: 2025-06-04 03:26:34