 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Sun Dec 18, 2016 4:44 pm Post subject: Is it possible to store an image in a variable? |
|
|
Is there any chance of a variable having a string, and this string is an image, and I open this image?
_________________
... |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25791 Location: The netherlands
|
Posted: Sun Dec 18, 2016 5:38 pm Post subject: |
|
|
the stringstream object is useful for this.
Code: |
ss=createStringStream('string')
p=createPicture()
p.loadFromStream(ss)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Sun Dec 18, 2016 5:54 pm Post subject: |
|
|
How can I get the string of an image?
_________________
... |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25791 Location: The netherlands
|
Posted: Sun Dec 18, 2016 6:03 pm Post subject: |
|
|
you can download it from a website. (the internet object in ce will download images as a string by default)
or I guess you could save the image as a table file and then do:
Code: |
s=createStringStream()
z=findTableFile('MyImage')
z.Stream.Position=0
s.CopyFrom(z.Stream,z.Stream.Size)
string=s.DataString
|
although if you already have the image in your table I don't know why you'd want it as a string because you can then just as well do:
Code: |
z=findTableFile('MyImage')
p=createPicture()
p.loadFromStream(z.Stream)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sun Dec 18, 2016 7:53 pm Post subject: |
|
|
Load picture image with a function
add a picture image on Table > add file
function 1
Load picture from stream (picture show as original and no border)
Code: | function attachBackground(wc,tblFile)
local p = createPicture()
p.loadFromStream(findTableFile(tblFile).Stream)
wc.OnPaint = function(sender)
local c = sender.getCanvas()
local bitmap = p.getBitmap()
c.draw(0,0,bitmap)
end
end
f = createForm(false)
attachBackground(f,[[MyPicture.jpg]])
f.show()
|
function 2
Load picture image from stream (with border and stretch)
Code: | function attachBackground(wc,tblFile,xoff,yoff,w,h,withBorderWidth)
if wc and wc.getCanvas then
rawset(_G,'bmCache',rawget(_G,'bmCache') or {})
if not bmCache[tblFile] then
local p = createPicture()
p.loadFromStream(findTableFile(tblFile).Stream)
bmCache[tblFile] = p.getBitmap()
end
local b = bmCache[tblFile]
xoff,yoff,w,h = xoff or 0,yoff or 0,w or b.Width, h or b.Height
wc.OnPaint = function(sender)
local c,bw=sender.Canvas,withBorderWidth == true and wc.BorderWidth or 0
c.copyRect(bw,bw,wc.Width-bw,wc.Height-bw,b.Canvas,xoff,yoff,xoff+w,yoff+h)
end
return true
else
return false,'the object has no canvas'
end
end
-- to draw withBorderWidth
f = createForm(false)
attachBackground(f,[[MyPicture.jpg]],nil,nil,nil,nil,true)
f.show()
|
|
|
Back to top |
|
 |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Mon Dec 19, 2016 4:48 am Post subject: |
|
|
I guess what I want to do is impossible.
It would be kind of like that. A variable would get an image, and using print () I would get the string that forms this image. Then it would get this string and assign it to a variable, and in the end it would show the image.
If this is not possible, how to store an image inside the .exe application.
(If that was what you said, I did not realize it)
_________________
... |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
|
Back to top |
|
 |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Dec 19, 2016 8:37 pm Post subject: |
|
|
Converting image to base64 image string.
Load decoded image using LuaSocket (mean need lua library ). No idea how to do this use pure lua (without "require")
By lua socket :
Code: |
local ltn12 = require "ltn12"
local mime = require "mime"
mystring = "somedata"
myoutfile = "out.gif"
ltn12.pump.all(
ltn12.source.string(mystring),
ltn12.sink.chain(
mime.decode("base64"),
ltn12.sink.file(io.open(outfile,"w"))
)
) |
Or doing using HTML5 code
Note :
http://principiagame.com/lua/img -- this for principia game, some command / statement are not recognized by pure lua 5.1, 5.2. 5.3 such as "draw_sprite_textel" - "this : sprite..", etc...
|
|
Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Mon Dec 19, 2016 9:12 pm Post subject: |
|
|
Base64 Encoded Image
Code: | function createPictureFromURL(url)
local http = getInternet()
local file = http.getURL(url)
http.destroy()
local picture = createPicture()
local stream = createStringStream(file)
picture.loadFromStream(stream)
return picture
end
function createPictureFromBase64(data)
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
data = string.gsub(data, '[^'..b..'=]', '')
data = (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
local picture = createPicture()
local stream = createStringStream(data)
picture.loadFromStream(stream)
return picture
end
if form == nil then
form = createForm(false)
end
if imgage == nil then
imgage = createImage(form)
end
if picture == nil then
picture = createPictureFromBase64("base64 encoded string")
--picture = createPictureFromURL("http://cheatengine.org/celogo.png")
imgage.setPicture(picture)
imgage.Height = 128
imgage.Width = 128
end
form.show() |
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Dec 19, 2016 10:32 pm Post subject: |
|
|
Zanzer, how to load image if Base64 Encoded Image stores as a bin file as CE stream file.
eq. "celogo.bin' ?
Thanks
|
|
Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Mon Dec 19, 2016 11:03 pm Post subject: |
|
|
If you're storing the file in the table, there's no reason to encode it in base64.
But if you must... use DB's code. Code: | s=createStringStream()
z=findTableFile('celogo.bin')
z.Stream.Position=0
s.CopyFrom(z.Stream,z.Stream.Size)
data=s.DataString
picture = createPictureFromBase64(data) |
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Tue Dec 20, 2016 5:52 am Post subject: |
|
|
i try :
Code: | url = "http://pastebin.com/sT9AAKm4"
file = "celogo.png"
function createPictureFromURL(url)
local http = getInternet()
local file = http.getURL(url)
http.destroy()
local picture = createPicture()
local stream = createStringStream(file)
picture.loadFromStream(stream)
return picture
end
function createPictureFromBase64(data)
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
data = string.gsub(data, '[^'..b..'=]', '')
data = (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
local picture = createPicture()
local stream = createStringStream(data)
picture.loadFromStream(stream)
return picture
end
if form == nil then
form = createForm(false)
end
if imgage == nil then
imgage = createImage(form)
end
if picture == nil then
picture = createPictureFromBase64(file)
-- picture = createPictureFromURL(url)
imgage.setPicture(picture)
imgage.Height = 128
imgage.Width = 128
end
form.show() |
- When tested result give "Error : Unknown picture format"
Next, I did my base64 encode image as a HTML file and store it as celogo.html on a online storage. This celogo.html if open with a browser will displaying "ce logo", withoutt any issue.
How load that celogo.html and executing with default browser using this "http = getInternet()" ?
I doing with local base64 image string :
i Code: | mg = [["iVBORw0KGgVWh3III/Uhlu ......... etc...etc .....RK5CYII="]]
function createPictureFromBase64(data)
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
data = string.gsub(data, '[^'..b..'=]', '')
data = (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
local picture = createPicture()
local stream = createStringStream(data)
picture.loadFromStream(stream)
return picture
end
if form == nil then
form = createForm(false)
end
if imgage == nil then
imgage = createImage(form)
end
if picture == nil then
picture = createPictureFromBase64(img)
--picture = createPictureFromURL("http://cheatengine.org/celogo.png")
imgage.setPicture(picture)
imgage.Height = 128
imgage.Width = 128
end
form.show() |
Thank you
Description: |
|
Filesize: |
16.46 KB |
Viewed: |
11531 Time(s) |

|
|
|
Back to top |
|
 |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Tue Dec 20, 2016 7:55 am Post subject: |
|
|
I gave up trying this
_________________
... |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Tue Dec 20, 2016 9:16 am Post subject: |
|
|
Code: | ---- Image file handle
path = "D://images.jpg" ---- put your image file name here (+ path / directory)
file = io.open(path, "rb")
image = file:read("*a")
---- Convert image to base64 encode string
function createBase64romPicture(data)
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end
bs64 = createBase64romPicture(image) --- creating base64 image
-- print(bs64)
img = tostring(bs64) --- store as string variable
---- Convert back Base64 image string as a image picture and show
function createPictureFromBase64(data)
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
data = string.gsub(data, '[^'..b..'=]', '')
data = (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
local picture = createPicture()
local stream = createStringStream(data)
picture.loadFromStream(stream)
return picture
end
if form == nil then
form = createForm(false)
end
if imgage == nil then
imgage = createImage(form)
end
if picture == nil then
picture = createPictureFromBase64(img)
imgage.setPicture(picture)
imgage.Height = 280
imgage.Width = 325
end
form.show() |
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|