Writing to files.

new BookmarkLockedFalling
Alyce
Administrator
*****

Alyce Avatar

Posts: 519Female

Post by Alyce on Jan 15, 2008 8:52:20 GMT -5

Not so much a bug as a caveat.

This demo uncovered a glitch:
runbasic.wikispaces.com/UploadAndMove

My first attempt at writing this code used a file opened for "output" to write filedata to a new file in a created folder. It worked okay for text files, but an attempt to write the data from a bmp file and from a wav file gave me an error:


unsupported character

The error went away when I attempted to write the data to a file opened for "binary." If files opened for output only work for text data, perhaps this should be documented.




-Alyce
mackrackit
Full Member
***

mackrackit Avatar

Posts: 231

Dave[br][br][url]http://www.mackrackit.com:8888[/url][br]
turbov21
Guest

Guest Avatar

mikeukmid
Guest

Guest Avatar

Post by mikeukmid on Jan 23, 2008 16:39:19 GMT -5

I have a jpg file which loads OK into a graphic using loadgraphic statement.
Copying the file, either opening for input/ouput or for binary results in a file which can not be loaded by loadgraphic, effectively leaving RB with no file copying facility.
The error message is 'Incompatible image. Marker C2 cannot be handled (possible unsupported progressive scan)'

Code used to copy:
file$="C:\rbp\webcamOFF.jpg"
open file$ for input as #f 'or binary
filedata$ = input$(#f, LOF(#f))
close #f
open "C:\rbp\webcam\webcamOFF.jpg" for output as #g 'or binary
print #g, filedata$ 'with or without semicolon
close #g



Mike
Last Edit: Jan 23, 2008 16:41:57 GMT -5 by mikeukmid
mackrackit
Full Member
***

mackrackit Avatar

Posts: 231

Dave[br][br][url]http://www.mackrackit.com:8888[/url][br]
mikeukmid
Guest

Guest Avatar

Post by mikeukmid on Jan 23, 2008 17:35:43 GMT -5

Dave,
Copying the file, either opening for input/ouput or for binary results in a file which can not be loaded by loadgraphic, effectively leaving RB with no file copying facility.


Thanks, but I have tried both input/output and binary.

Mike
mackrackit
Full Member
***

mackrackit Avatar

Posts: 231

Post by mackrackit on Jan 23, 2008 21:00:06 GMT -5

Mike,

I just used this and it worked here.

file$="C:\rbp\hi.jpg"
open file$ for binary as #f
filedata$ = input$(#f, LOF(#f))
close #f
open "C:\rbp\webcam\hi.jpg" for binary as #g 'or binary
print #g, filedata$ 'with or without semicolon
close #g

'Load the image
loadimage "banner", "hi.jpg"

'create a graphic object.
graphic #g, 420, 300

'draw the image in the graphic object.
#g drawimage("banner",0,0)

'display it on the web page
render #g
Dave[br][br][url]http://www.mackrackit.com:8888[/url][br]
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

Post by StefanPendl on Jan 23, 2008 23:42:53 GMT -5

mackrackit said:
Mike,

I just used this and it worked here.

file$="C:\rbp\hi.jpg"
open file$ for binary as #f
filedata$ = input$(#f, LOF(#f))
close #f
open "C:\rbp\webcam\hi.jpg" for binary as #g 'or binary
print #g, filedata$ 'with or without semicolon
close #g

'Load the image
loadimage "banner", "hi.jpg"

'---snip

You are displaying the original image.
If you use relative, existing paths, anyone can run your snip, without modification.
The following uses PRINT with and without semicolon, an image included in the RBP installation and the temporary image folder, so it can be run on any RBP installation.
file$="mandelbrot.jpg"
open file$ for binary as #f
filedata$ = input$(#f, LOF(#f))
close #f
open "public\images\copy_test_0.jpg" for binary as #g 'or binary
print #g, filedata$ 'without semicolon
close #g
open "public\images\copy_test_1.jpg" for binary as #g 'or binary
print #g, filedata$; 'with semicolon
close #g

'Load the image
loadimage "banner", "public\images\copy_test_0.jpg"
loadimage "banner1", "public\images\copy_test_1.jpg"

'create a graphic object.
graphic #g, 400, 600

'draw the image in the graphic object.
#g drawimage("banner",0,0)
#g drawimage("banner1",0,300)

'display it on the web page
render #g

This example gives no errors and the images are displayed correctly.
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
mackrackit
Full Member
***

mackrackit Avatar

Posts: 231

Post by mackrackit on Jan 24, 2008 5:58:17 GMT -5

OOPPS, I was opening the original file.

Made a change
Killed the original
opened the correct image
Now it works!

file$="C:\rbp\hi.jpg"
open file$ for binary as #f
filedata$ = input$(#f, LOF(#f))
close #f
open "C:\rbp\webcam\hi.jpg" for binary as #g
print #g, filedata$ 'with or without semicolon
close #g

kill file$

'Load the image
loadimage "banner", "C:\rbp\webcam\hi.jpg"

'create a graphic object.
graphic #g, 420, 300

'draw the image in the graphic object.
#g drawimage("banner",0,0)

'display it on the web page
render #g
Dave[br][br][url]http://www.mackrackit.com:8888[/url][br]
mikeukmid
Guest

Guest Avatar

Post by mikeukmid on Jan 24, 2008 5:58:59 GMT -5

Thanks everybody, but did you notice I was using loadgraphic not loadimage? ;)

After a fresh start today I realised the file I was copying was not the one intended. It was a progressive scan jpg - hence the error message was correct.

All's well now ... for now. ;D

Mike.
Last Edit: Jan 24, 2008 6:15:07 GMT -5 by mikeukmid