Image from Memory

Hiya,

atm I am trying to load an image from a SQLite-database.
My code successfully gets the blob-data from the database, saves it to maps.jpg, and loads the jpg afterwards to display. I’d like to remove the need of saving and reloading of the image.

[lua]require “sqlite3”
local path = system.pathForFile(“test.db”, system.ResourceDirectory)
– test.db contains one table which holds a text in mytext TEXT and maps.jpg in binary BLOB
db = sqlite3.open( path )

local function onSystemEvent( event )
if( event.type == “applicationExit” ) then db:close() end
end

for row in db:nrows(“SELECT * FROM entry”) do
local text = row.mytext
local t = display.newText(text, 20, 30 * row.id, null, 16)
t:setTextColor(255,0,255)

– this works, but how can I get the image directly from row.binary
– so I could remove from here …
local tmp = io.output() – save current file handle
local path = system.pathForFile( “temp.jpg”, system.TemporaryDirectory )
io.output( path ) – open new file in text mode
io.write( row.binary ) – write the file
io.output():close() – close the file
io.output( tmp )
local t2 = display.newImage( “temp.jpg”, system.TemporaryDirectory, 124, 24 )
– until here…
end

Runtime:addEventListener( “system”, onSystemEvent )[/lua]

Any ideas?
Thanks in advance :slight_smile:

Best regards
J. [import]uid: 10612 topic_id: 9312 reply_id: 309312[/import]