Posted: 24th Feb 2003 19:40
If you don't want to use DLLs try this:
Technically this code will "save the bitmap",
although it is of no use to anyone who doesn't use DBPro to read it.
+ Code Snippet
Open To Write File_num,Filename$
Make Memblock From Bitmap MB_num,BM_num
Write Memblock File_num,MB_num
Close File File_num

To load it.
+ Code Snippet
Open To Read File_num,Filename$
Make Memblock From File File_num,MB_num
Close File File_num
Make Bitmap From Memblock  BM_num,MB_num

You could use Images instead of Bitmaps.
Posted: 24th Feb 2003 21:02
That's very clever, never thought of that before
Posted: 25th Feb 2003 5:41
thats is very clever, wished I'ld thought of it. lol
good job,
CTP
Posted: 25th Feb 2003 6:01
ROFL!!! I was contemplating learning the BMP file format and coding my own exporter... The answer is SO SIMPLE!
Posted: 25th Feb 2003 8:27
Actually I didn't think that this would be of much use to anyone. I just posted it off the top of my head because I used the technique before and I didn't actually check the code till now after I saw the positive responses.

I made a mistake in the pseudo code to reload the image. The reload of the image won't work as I posted it.
The correct code uses a Read Memblock File_num,MB_num call instead of the Make Memblock From File function. The bitmap file creation code was OK.
+ Code Snippet
Open To Read File_num,Filename$
Read Memblock File_num,MB_num
Close File File_num
Make Bitmap From Memblock  BM_num,MB_num



Hope it didn't cause anybody problems.
Posted: 25th Feb 2003 9:31
or you could use

+ Code Snippet
// declarations
type RGB3_t
   red   as byte
   green as byte
   blue  as byte
endtype

function save_bitmap( strBitmap as string, wBitmap as word )
`// private declarations
local dwPixel  as RGB3_t
local dwPos    as dword
local dwPos2   as dword
local memblock as dword = wBitmap + 1

`// create memblocks
make memblock from image wBitmap,wBitmap
make memblock memblock,(memblock dword(wBitmap,0)*memblock dword(wBitmap,4))*3 + 11 + 16

`// write header
`// info data
write memblock byte memblock,dwPos,( asc("M")<<8 ) + asc("B")        : inc dwPos
write memblock dword memblock,dwPos,get memblock size(memblock)      : inc dwPos,4
write memblock byte memblock,dwPos,0                                 : inc dwPos
write memblock byte memblock dwPos,0                                 : inc dwPos
write memblock dword memblock,dwPos,28                               : inc dwPos,4

`// core data
write memblock dword memblock,dwPos,16                               : inc dwPos,4
write memblock dword memblock,dwPos,memblock dword(wBitmap,dwPos-4)  : inc dwPos,4
write memblock dword memblock,dwPos,memblock dword(wBitmap,dwPos-4)  : inc dwPos,4
write memblock word memblock,dwPos,1                                 : inc dwPos,2
write memblock word memblock,dwPos,24

dwPos = memblock dword(memblock,7) :`// grab offset value
dwPos2 = 12

`// write data
for indexX = 0 to memblock dword(wBitmap,0) - 1
   for indexY = 0 to memblock dword(wBitmap,4) - 1
   `// read data
      dwPixel.red = memblock byte(wBitmap,dwPos2)        : inc dwPos2
      dwPixel.green = memblock byte(wBitmap,dwPos2)      : inc dwPos2
      dwPixel.blue = memblock byte(wBitmap,dwPos2)       : inc dwPos2,2
   `// write data
      write memblock byte memblock,dwPos,dwPixel.red     : inc dwPos
      write memblock byte memblock,dwPos,dwPixel.green   : inc dwPos
      write memblock byte memblock,dwPos,dwPixel.blue    : inc dwPos
   next indexY
next indexX

`// save bitmap
open to write strBitmap,1
   make file from memblock 1,memblock
close file 1

`// clear memory
delete memblock wBitmap : delete memblock memblock
endfunction


for some reason my pro IDE doesn't recognise "make file from memblock" only "make file" - possibly a bug cause the function is still in the manual

from the info header see when i write from the previous memblock thats the Width and Height ... and then you have the bits per pixel - however you need to change that to 32
Posted: 25th Feb 2003 9:32
just incase you don't know that will export to a readable 24bit Microsoft Windows Bitmap
Posted: 25th Feb 2003 17:20
Cool. A couple of compile bugs though.

You missed a comma,
write memblock byte memblock dwPos,0

open to write strBitmap,1
should be
open to write 1,strBitmap

I'll test it later. This is nice code as it's uncompiled.

On what page in the manual is that << function defined?
??= modulo remainder?
Posted: 25th Feb 2003 18:23
Values and Operators
Posted: 25th Feb 2003 23:58
I don't have that page in my North American manual.
What is the operator's name and function?
Posted: 26th Feb 2003 3:40
<< BitShift Left
>> BitShift Right

its in the online manual
Posted: 26th Feb 2003 6:41
ONLINE MANUAL?
There are mystery commands in a mystery online manual?


I see no mention of any online manual on this web site.

Just where is this mystery manual hidden?
Posted: 26th Feb 2003 6:47
did u mean this glossary at RGT?

http://www.realgametools.net/glossary/
Posted: 26th Feb 2003 7:23
no... just press F1
Posted: 26th Feb 2003 7:58
so u mean the inbuilt manual?
Posted: 26th Feb 2003 8:25
ya built-in i guess
i've always called the paper one the "manual" and the one packaged with DB the "online" one ... kinda figured others around here were too. Didn't know RGT had one actually online lol
Posted: 16th Mar 2003 1:30
Raven. why am I getting "Memblock range is illegal" when I try to run your code?
Also, am I using it correctly?

save_bitmap("Test.bmp",6400)

in this bit of code:

+ Code Snippet
if mouse_click_menu() = "Save"
create bitmap 6400,800,600
set current bitmap 6400
cls
sprite 2000,xs1,ys1,10
sprite 2001,xs2,ys2,11
sync
save_bitmap("Test.bmp",6400)
endif


Thanks
Posted: 17th Mar 2003 20:38
Memblock numbers range from 1 to 256 - use a smaller number for your bitmap, or change Ravens code to us a specific memblock number.
Posted: 21st Mar 2003 17:30
oops! :-s thx!