AylinCE Grandmaster Cheater Supreme
Reputation: 35
Joined: 16 Feb 2017 Posts: 1478
|
Posted: Wed May 05, 2021 3:41 am Post subject: Upload, store, use to the table from the official URL. V2 |
|
|
Upload images from URL to table, store and use as needed.
It would be wise to give this a use case in this archive.
Here is an example;
Code: | if frm2 then frm2.Destroy() frm2=nil end
frm2=createForm()
frm2.Caption = "Sample load Picture"
frm2.Position = "poDesktopCenter"
local FrmImg1 = createImage(frm2)
FrmImg1.Left=20 FrmImg1.Height=100 FrmImg1.Top=40 FrmImg1.Width=120
FrmImg1.Stretch=true FrmImg1.Visible=true
local FrmImg2 = createImage(frm2)
FrmImg2.Left=180 FrmImg2.Height=100 FrmImg2.Top=40 FrmImg2.Width=120
FrmImg2.Stretch=true FrmImg2.Visible=true
local btn1=createButton(frm2)
btn1.left=110 btn1.top=190 btn1.Width=95 btn1.caption="LoadImage"
-----------------------------------------
local loadUrl = getInternet().getURL
function crtPicture(link1)
logostr22=loadUrl(link1)
local ss22=createStringStream(logostr22)
p=createPicture()
p.loadFromStream(ss22)
ss22.destroy()
return p
end
picture1 = crtPicture("http://i.hizliresim.com/g3z88z.png")
picture2 = crtPicture("http://i.hizliresim.com/77cyhu.png")
local rep=1
btn1.OnClick=function()
if rep==1 then
FrmImg2.picture=picture2
FrmImg1.picture=picture1
rep=2
else
FrmImg1.picture=picture2
FrmImg2.picture=picture1
rep=1
end
end |
--#################################--
V2:
* Creates a folder on the desktop.
* Downloads pictures from url to folder.
* Checks whether the folder exists at every startup.
* If there is a folder, it does not download it again, it uses the pictures in the current folder.
* Note: If the pictures in the folder are deleted or their names are changed, the upload will start from the beginning.
Code: | if frm2 then frm2.Destroy() frm2=nil end
frm2=createForm()
frm2.Caption = "Sample load Picture"
frm2.Position = "poDesktopCenter"
local FrmImg1 = createImage(frm2)
FrmImg1.Left=20 FrmImg1.Height=100 FrmImg1.Top=40 FrmImg1.Width=120
FrmImg1.Stretch=true FrmImg1.Visible=true
local FrmImg2 = createImage(frm2)
FrmImg2.Left=180 FrmImg2.Height=100 FrmImg2.Top=40 FrmImg2.Width=120
FrmImg2.Stretch=true FrmImg2.Visible=true
local btn1=createButton(frm2)
btn1.left=110 btn1.top=190 btn1.Width=95 btn1.caption="LoadImage"
if RpTimer1 then RpTimer1.destroy() RpTimer1=nil end
RpTimer1=createTimer() RpTimer1.Interval=1000 RpTimer1.Enabled=false
--######################################################--
local pict1=""
local pict2=""
local timerIndex=0
local checkFile=1
local fd = os.getenv("USERPROFILE").."\\Desktop"
local pth22=fd..[[\PicFolder]]
function loadUrl(link)
local int=getInternet()
s=int.getURL(link)
int.destroy()
return s
end
function Path22()
os.execute([[mkdir "]]..fd..[[\PicFolder"]])
end
function pathExist(fl)
local check = os.execute([[cd "]]..fd.."\\"..fl)
if not check then --print("Folder doesnt exist")
checkFile=2
timerIndex=0
Path22()
RpTimer1.Enabled=true
else
--print("Folder exist")
checkFile=1
timerIndex=1
RpTimer1.Enabled=true
end
return fl
end
function pathExist1(fl2)
local check = os.execute([[cd "]]..fd.."\\"..fl2)
if not check then --print("Folder doesnt exist")
checkFile=2
timerIndex=0
Path22()
RpTimer1.Enabled=true
else
--print("Folder exist")
checkFile=1
end
return fl2
end
pathExist("PicFolder")
function DownImage()
FrmImg1.picture=pict2
FrmImg2.picture=pict1
end
function crtPicture(link1,file1)
logostr22=loadUrl(link1)
local ss22=createStringStream(logostr22)
p=createPicture()
if p then
p.loadFromStream(ss22)
aa=file1..".png"
aa1=p
aa1.saveToFile(pth22..'\\'..aa)
ss22.destroy()
return p
end
end
function crtPicture22(link1,name1)
pngFile=link1.."\\"..name1..".png"
--print("pngFile -- "..pngFile)
pathPng=pathExist1(pngFile)
p1=createPicture()
p1.LoadFromFile(link1)
return p1
end
function loadFile22()
if checkFile==2 then
RpTimer1.Enabled=true
else
pict1=crtPicture22(pth22..[[\pict1.png]],"pict1")
pict2=crtPicture22(pth22..[[\pict2.png]],"pict2")
RpTimer1.Enabled=true
end
end
function LoadPicture()
pict1 = crtPicture("http://i.hizliresim.com/g3z88z.png","pict1")
pict2 = crtPicture("http://i.hizliresim.com/77cyhu.png","pict2")
RpTimer1.Enabled=true
end
RpTimer1.OnTimer=function()
timerIndex=tonumber(timerIndex) + 1
--print("timerIndex "..timerIndex)
if timerIndex==1 then
LoadPicture() end
if timerIndex==2 then
loadFile22() end
if timerIndex==3 then
DownImage()
RpTimer1.Enabled=false end
end
local rep=1
btn1.OnClick=function()
if rep==1 then
FrmImg2.picture=pict2
FrmImg1.picture=pict1
rep=2
else
FrmImg1.picture=pict2
FrmImg2.picture=pict1
rep=1
end
end
|
See you in another useful archive.
Enjoy it.
|
|