hey i'm making a paint program (yet another one of my bordom inspired projects) and i am giving it the ability to save to bmp images, i have already made the part where it saves, however, true basic keeps adding line breaks (ascii code 13) to the file, is there any way around this?
Comments
accually no i was using
accually no i was using print#1:
i was writing the files using what i have found on the internet about bmp images, the print was adding carrage returns to the file when i did not tell it to
my code:
SUB save(n$,l,px,py,d$)
DIM fs(4),tfs(4),dx(4),dy(4)
LET l=len(n$)
IF lcase$(n$[l-3:l])<>".bmp" then
LET n$=n$ & ".bmp"
END IF
OPEN#1: NAME n$ ,ACCESS outin, CREATE newold
ERASE #1
LET sx=px
DO until sx/4=int(sx/4) !byte padding
LET sx=sx+1
LOOP
LET sy=py
!finding the file size
LET temp=len(d$)/3
FOR x=4 to 1
LET s=0
DO until temp<16^(4-x)
LET s=s+1
LET temp=temp-16^(4-x)
LOOP
LET fs(x)=s*(16^(4-x))
NEXT x
!finding the total file size
LET temp=len(d$)/3+54
FOR x=4 to 1
LET s=0
DO until temp<16^(4-x)
LET s=s+1
LET temp=temp-16^(4-x)
LOOP
LET fs(x)=s*(16^(4-x))
NEXT x
LET temp=sx !x width
FOR x=4 to 1
LET s=0
DO until temp<16^(4-x)
LET s=s+1
LET temp=temp-16^(4-x)
LOOP
LET dx(x)=s*(16^(4-x))
NEXT x
LET temp=sy !y width
FOR y=4 to 1
LET s=0
DO until temp<16^(4-y)
LET s=s+1
LET temp=temp-16^(4-y)
LOOP
LET dy(y)=s*(16^(4-y))
NEXT y
FOR x=1 to len(d$) step 3
LET t$=t$ & chr$(val(d$[x:x+2]))
NEXT x
LET temp$="BM" !0-1
LET temp$=temp$ & chr$(tfs(1)) & chr$(tfs(2)) & chr$(tfs(3)) & chr$(tfs(4)) !2-5
LET temp$=temp$ & chr$(0) & chr$(0) & chr$(0) & chr$(0) !6-9
LET temp$=temp$ & chr$(54) & chr$(0) & chr$(0) & chr$(0) !10-13
LET temp$=temp$ & chr$(40) & chr$(0) & chr$(0) & chr$(0) !14-17
LET temp$=temp$ & chr$(dx(1)) & chr$(dx(2)) & chr$(dx(3)) & chr$(dx(4)) & chr$(dy(1)) & chr$(dy(2)) & chr$(dy(3)) & chr$(dy(4)) !18-25
LET temp$=temp$ & chr$(1) & chr$(0) !26-27
LET temp$=temp$ & chr$(24) & chr$(0) !28-29
LET temp$=temp$ & chr$(0) & chr$(0) & chr$(0) & chr$(0) !30-33
LET temp$=temp$ & chr$(fs(1)) & chr$(fs(2)) & chr$(fs(3)) & chr$(fs(4)) !34-37
LET temp$=temp$ & chr$(19) & chr$(11) & chr$(0) & chr$(0) & chr$(19) & chr$(11) & chr$(0) & chr$(0) !38-45
LET temp$=temp$ & chr$(0) & chr$(0) & chr$(0) & chr$(0) !46-49
LET temp$=temp$ & chr$(0) & chr$(0) & chr$(0) & chr$(0) !50-53
LET temp$=temp$ & t$
PRINT #1: temp$
END SUB
d$ is the rgb values already organized and converted to characters with chr$ in the main program
Wrong file type for n$ ...
jackduffybailey ... Your OPEN #1: program line should be as follows:
OPEN#1: NAME n$ ,ORG byte, ACCESS outin, CREATE newold
because your n$ file is the default 'text' file type. A 'text' file can modify what goes into n$, without you knowing it.
With a 'ORG byte' fille type, nothing can add or delete any thing to n$ unless you do the add or delete. Regards ... Tom M
ok thanks, but i had looked
ok thanks, but i had looked in the true basic help by pressing F1 and i had seen that, i thought that looked right and had already tried that, thanks for verifying this but i still get an error: "Can't PRINT to INTERNAL file. (7317) 99 in save,142 in main program"
Can't print to internal file ...
jackduffybailey ... Sorry about that; you can't use PRINT or INPUT statements with byte files, only with text files.
You must use READ and WRITE stateements with byte files. Regards ... Tom M
thanks
thanks (they work the same way right?)
No, they don't ...
jackduffybailey ... No, text files don't work like byte files at all. As I like to say, "Read the Manual!!".
A byte file is nothing more than a string variable that can consist of any of the 256 ASCII characters. When I open a byte file, I READ the file into string variable y$. In one case I remember, the length of y$ was more than 950,000 bytes long, and it was a text file.
You can OPEN a Microsoft Word file or an Excel file as a byte file in True BASIC; you won't create a single error event. You can "PARSE" any TB byte file to see what's in it, and you can extract sections of the target byte file; I do that frequently. Regards ... Tom M
no no no not the file, the
no no no not the file, the write and read statements
and anyways, now there is a
and anyways, now there is a subscript out of bounds error:
array is set in this block:
ASK PIXELS px,py
LET px=px+1
LET py=py+1
MAT redim colors(l,px,py,1 to 4)
and the error is in this block
LET l=1
...
FOR y=1 to py
FOR x=1 to px
FOR c=3 to 1 step -1
LET t$=str$(colors(l,x,y,c)) !at this line
note that the 4 in the redim is for opacity when i add in the extra layer functions
that would be a yes
that would be a yes
writing BMP images
Hi,
I assume you are using:
CALL writeImage("MS BMP",imagedata$,filename$)
where imagedata$ is the string produced by:
BOX KEEP left,right,bottom,top IN imagedata$
Images can be recovered and shown with:
CALL readImage("MS BMP",imagedata$,filename$)
Big John
oops, i missed the button,
oops, i missed the button, see above for reply