@HyroVitalyProtago Here’s some code that will create an image file and read it back. It accounts for retina images. I don’t like the imageCreate function, maybe I’ll redo it later.
function setup()
img=readImage("Platformer Art:Block Special")
w=img.rawWidth
h=img.rawHeight
createFile()
readFile()
createImage()
end
function draw()
background(0)
sprite(img,WIDTH/2,HEIGHT/4)
if img1~=nil then
sprite(img1,WIDTH/2,HEIGHT/2)
end
end
function createFile()
print("create file")
file = os.getenv("HOME").."/Documents/Dropbox.assets/test.txt"
f=io.open(file,"w") -- open file and delete anything in it.
f=io.open(file,"a+") -- open file for append
f:write("("..w..","..h..")") -- write the width and height
for x=1,w do
for y=1,h do
r,g,b,a=img:rawGet(x,y)
str=string.format("(%f,%f,%f,%f)",r,g,b,a)
f:write(str) -- append the r,g,b,a values
end
end
f:close() -- close the file
print("create file done")
end
function readFile()
print("read file")
file = os.getenv("HOME").."/Documents/Dropbox.assets/test.txt"
a=io.open(file,"r")
fil=a:read("a")
a:close() -- close the file
print"read file done"
end
function createImage()
print("create image")
tab={}
xx=""
w,h=nil,nil
for z=1,#fil do
v=string.sub(fil,z,z)
if v=="(" then
r,g,b,a=nil,nil,nil,nil
xx=""
elseif v=="," or v==")" then
val=tonumber(xx)
if w==nil then
w=val
elseif h==nil then
h=val
elseif r==nil then
r=val
elseif g==nil then
g=val
elseif b==nil then
b=val
elseif a==nil then
a=val
table.insert(tab,vec4(r,g,b,a))
end
xx=""
else
xx=xx..v
end
end
img1=image(w,h)
cnt=0
for x=1,w do
for y=1,h do
cnt=cnt+1
img1:rawSet(x,y,tab[cnt].x,tab[cnt].y,tab[cnt].z,tab[cnt].w)
end
end
print("create image done")
end