Hello,
Well, the first thing you have to know is the difference between BYTE, WORD, and DWORD and how they relate to the screen resolution. Since 8bit is so rare these days, you probably won't be reading back a pixel's color as a single BYTE. If your resolution is 16 bit, then you most likely will be reading the color data back as a WORD, and if your resolution is 24 or 32 bit, then you will most likely be reading back the color information as a DWORD.
So far so good?
Next, I usually use MAKE MEMBLOCK FROM IMAGE instead of from bitmap just because it's easier for me to deal with, and it allows me to size the image however I want.
The structure in the memblock once you have used MAKE MEMBLOCK FROM IMAGE is
Header
DWORD - Image Width (4 bytes - lowbyte to highbyte)
DWORD - Image Height (4 bytes - lowbyte to highbyte)
DWORD - Image Depth (4 bytes - lowbyte to highbyte)
Data
Pixel data - based on the depth (BYTE, WORD, or DWORD)
Here's an example of taking a look at what's inside the memblock after converting a 1 pixel image (green by the way) to a memblock at 16 bit resolution:
set display mode 640,480,16
cls 0
ink rgb(0,255,0),0
dot 0,0
get image 1,0,0,1,1
make memblock from image 1,1
size=get memblock size(1)
rem look at memblock data
for pos=0 to size-1
print memblock byte(1,pos);" ";
next pos
After you run this you see
1 0 0 0 1 0 0 0 16 0 0 0 224 7
Which means width=1 height=1 depth=1 and pixel is a WORD = green
Once you convert the memblock, you'll need it's size so that you know how big to make a loop to read back the information to the screen. This information is given back in total bytes. So remember that the header is 12 bytes long(3 DWORDs) and that each pixel will have a size based on depth. So in the previous example, if I want to reassemble the bitmap, I have to look at the header, and determine the bitdepth so I know what data type I will read back from the memblock for each pixel. Here's an example using 32 bitdepth:
set display mode 640,480,32
sync on
sync rate 0
cls 0
rem create an image
ink rgb(0,255,0),0
box 0,0,50,50
ink rgb(255,0,0),0
box 10,10,70,70
ink 255,0
box 20,10,30,100
get image 1,0,0,71,101
rem make a memblock of the image
wait 50
make memblock from image 1,1
size=get memblock size(1)
repeat
Text 100,100,"Press space to continue..."
sync
until spacekey()=1
cls 0
sync
rem write memblock data back to screen
rem position 0 = width
rem position 4 = height
rem position 8 = depth
rem position 12 = start of pixel data
rem let's get our x and y from width and height
width=memblock dword(1,0)
height=memblock dword(1,4)
rem even though we know we converted the image at 32 bit
rem let's look in the memblock header to get the bit depth
depth=memblock dword(1,8)
if depth = 8 then dtype=1 : rem dtype is data type in this case BYTE
if depth = 16 then dtype=2 : rem dtype is data type in this case WORD
if depth = 24 then dtype=4 : rem dtype is data type in this case DWORD
if depth = 32 then dtype=4 : rem dtype is data type in this case DWORD
rem now write it back to the screen
pos=12-dtype
for y=0 to height-1
for x=0 to width-1
rem check for data type so we know how to handle the memblock
if dtype=1
inc pos,dtype
color=memblock byte(1,pos)
endif
if dtype=2
inc pos,dtype
color=memblock word(1,pos)
endif
if dtype=4
inc pos,dtype
color=memblock dword(1,pos)
endif
rem draw
ink color,0
dot x,y
sync :rem delete this sync for faster refresh (not pixel by pixel)
next x
next y
sync
[EDIT]
16bit is actually a bit more complicated because of the color conversion and the example program won't quite work right unless you add a conversion routine. If you search the web for RGB565 or 16bit RGB you'll find tons of information on how to deal with this. Here's a link to a thread I had started regarding the 16bit conversion:
http://forum.thegamecreators.com/?m=forum_view&t=105474&b=10
Enjoy your day.