Taking it a little further - by scanning rows, I have increased capacity to 18 kbytes
within a 200 x 200 image. At the quality level used by Apple, jpegs have
not caused any errors in reading of data. At higher compression ratios
I would expect errors to appear.
Here is the revised code and the changed screenshots for writing
and reading plus the data image.
In the text, I mention that emoji can be printed by substituting them for standard ASCII characters. To see this work, look for the code lines that replace characters [ ] and ^ Currently I have to set them to "" because the Forum will not accept emoji. But you can insert any that you wish into the 3 "" and see them display
Code: Select all
' Datastore Sync
' based on Datastore by Henko
' October 2016
SET ORIENTATION LANDSCAPE
laun$=LAUNCHER$ ()
GET SCREEN SIZE sw,sh
dev$=DEVICE_TYPE$()
iostest=0 ' set to 1 to test other iOS devices on iPad
IF iostest THEN
dev$=""
sw=667!sh=375 ' to test iPhone 6
ENDIF
rw=sw/1024!rh=sh/768
le=20000
GRAPHICS ! ss=SCREEN_SCALE()
send=0
IF send THEN
a$="We have a very chilly Fall here in Calgary."&CHR$(10)
a$&="I am testing the data storage."&CHR$(10)
a$&="I am going to save an image and export it to the camera roll."&CHR$(10)
a$&="I will include some emoji: [ ] ^ ."&CHR$(10)
FOR m=1 TO 100
a$&="We have a very chilly Fall here in Calgary."&CHR$(10)
a$&="I am testing the data storage."&CHR$(10)
a$&="I am going to save an image and export it to the camera roll."&CHR$(10)
a$&="I will include some emoji: [ ] ^ ."&CHR$(10)
NEXT m
le=LEN(a$)
FIELD "input" TEXT a$ AT 50*rw,220*rh SIZE 800*rw,260*rh ML RO
DRAW FONT SIZE 14*rw
DRAW TEXT "imagedata1.jpg" AT 0,190*rh
DRAW FONT SIZE 20*rw
DRAW TEXT "Write" AT 880,290*rh
DRAW TEXT "data to" AT 880,310*rh
DRAW TEXT "screen" AT 880,330*rh
lin=-8!k=0
FOR i=0 TO le-1
IF i%400=0 THEN! lin+=8!k=0!ENDIF
draw_num(k,lin,ASC(MID$(a$,i,1)))
k+=1
NEXT i
GRAPHICS SAVE 0,0, 200,200 TO "imagedata1.jpg"
ALBUM EXPORT "imagedata1.jpg"
ELSE
ALBUM IMPORT "imagedata2.jpg"
DRAW IMAGE "imagedata2.jpg" AT 0,0 SCALE .5
ENDIF
'le=1000
DRAW TEXT "Read" AT 880,560*rh
DRAW TEXT "data from" AT 880,580*rh
IF send THEN
DRAW TEXT "screen" AT 880,600*rh
ELSE
DRAW TEXT "saved" AT 880,600*rh
DRAW TEXT "image" AT 880,620*rh
ENDIF
lin=-8!k=0
FOR i=0 TO le-1
IF i%400=0 THEN! lin+=8!k=0!ENDIF
temp$ =CHR$(get_num(k,lin))
IF temp$="]" THEN temp$=""
IF temp$="[" THEN temp$=""
IF temp$="^" THEN temp$=""
b$ &= temp$
k+=1
NEXT i
FIELD "output" TEXT b$ AT 50*rw,500*rh SIZE 800*rw,260*rh ML RO
PAUSE 10
END
DEF draw_num(x,y,num)
FOR i=0 TO 7
IF BIT(num,i) THEN DRAW PIXEL x,y+i
NEXT i
END DEF
DEF get_num(x,y)
num=0
FOR i=0 TO 7
GET PIXEL x,y+i COLOR r,g,b
IF r+g+b>2.5 THEN num+=2^i
NEXT i
RETURN num
END DEF
The only thing that gets me down is gravity...