I did some tests and the image type is determined by the filename extension (e.g. .jpg, .jpeg, .png).
Even if the type specifies something different (e.g. filename=“image.jpg” but type=“image/png”), the file type being saved is still determined by the filename extension, i.e. it’s a JPEG in this example and not a PNG.
When I used filename=“DemoImage” as in your example, I got “file not found” error when reading it using file:read().
Here’s how I determine the image type:
[lua]local fname = “tmpImg.jpg”
local dir = system.TemporaryDirectory
local function readFile()
local path = system.pathForFile( fname, dir )
local file, errorString = io.open( path, “rb” )
if not file then
print( "File error: " … errorString )
else
local firstByte = string.byte(file:read(1))
if firstByte==255 then
print(“image/jpeg”)
elseif firstByte==137 then
print(“image/png”)
elseif firstByte==71 then
print(“image/gif”)
elseif firstByte==73 or firstByte==77 then
print(“image/tiff”)
end
io.close( file )
end
file = nil
end
local function imageSelectedListener( event )
if event.completed then
readFile()
end
end
media.selectPhoto(
{
mediaSource = media.PhotoLibrary,
listener = imageSelectedListener,
destination = { baseDir=dir, filename=fname, type=“image” }
})
[/lua]
Although the code considers gif and tiff, I couldn’t save those types.
Dave