Can't load from Documents or Temp directory

The code:

local path = system.pathForFile(“myimage.jpg”, system.DocumentsDirectory)
local image = display.newImage(path)

The response:

WARNING: Failed to find image(/Users/mark/Library/Application Support/Corona Simulator/image_trim-C3A1B2DB4616B8CAB2A54233D757EDE8/Documents/myimage.jpg)

Check file really exists:

~ mark$ ls “/Users/mark/Library/Application Support/Corona Simulator/image_trim-C3A1B2DB4616B8CAB2A54233D757EDE8/Documents/myimage.jpg”

Yes, it does (ls response):

/Users/mark/Library/Application Support/Corona Simulator/image_trim-C3A1B2DB4616B8CAB2A54233D757EDE8/Documents/myimage.jpg

Path has spaces. Let’s wrap it in quotes:

local path = system.pathForFile(“myimage.jpg”, system.DocumentsDirectory)
local image = display.newImage(""" … path … “”")

WARNING: Failed to find image("/Users/mark/Library/Application Support/Corona Simulator/image_trim-C3A1B2DB4616B8CAB2A54233D757EDE8/Documents/myimage.jpg")

Nope.

In previous SDK versions this worked as expected, but not now. How come?

It’s easy to get around for newImage, as you just pass the base directory parameter, but it you want to load a sprite sheet you’re stuck with the old syntax and it won’t load.

Would appreciate help or confirmation that this is - or isn’t - a problem. [import]uid: 3953 topic_id: 6316 reply_id: 306316[/import]

I’ll asume that the myimage.jpg is a file that you already have and is Not being downloaded at runtime. If this is the case, you need to put the jpg in the same folder as the main.lua file.

The Application Support / Corona directory is used for the sim at runtime, you should not need to modify files in there manually since the app is going to adjust them anyway. [import]uid: 7727 topic_id: 6316 reply_id: 22866[/import]

Thanks for the feedback but I’m not sure if I follow.

Example: I create an image and save to Documents (or the corresponding folder in the sim).

I can load this file, but not with the sprite loader and not using the newImage syntax where you construct a path with pathForFile.

As I understand it, the default location (i.e without a path specified) for loading and saving is Resources, but saving there would invalidate the app. [import]uid: 3953 topic_id: 6316 reply_id: 23112[/import]

MarkHenryC,

I understand what you mean… If you want to save an image file at run time you’r only choice is ‘documents’.

In the simulator the ‘sandbox’ is ‘documents’.

So are you saying that even in the simulator you cannot load from ‘documents’ with the spriteloader or new image syntax?

[import]uid: 8872 topic_id: 6316 reply_id: 23253[/import]

If you create an image, and plan to put it in your app( pre-compile time ), you put the image in the same folder that your source code is in, Not in the /Libarary/App Support/Corona folder.

I typically make a folder called GFX in the project folder.

If you look at the Twitter app on this site ( http://developer.anscamobile.com/content/twitter )

You can see on line 15 where it says ‘local background = display.newImage( “tweetscreen.png” )’
The tweenscreen image is in the same directory as main.lua. [import]uid: 7727 topic_id: 6316 reply_id: 23247[/import]

@ SyndicatePlus: as kam187 observed, the image is created at runtime. [import]uid: 3953 topic_id: 6316 reply_id: 23354[/import]

Just got feedback from Ansca after sending a test file. The answer is nice and simple:

local spriteSheet_from_temp = sprite.newSpriteSheet(TEMP_IMAGE, system.TemporaryDirectory, CELLX, CELLY)
local spriteSheet_from_docs = sprite.newSpriteSheet(DOCS_IMAGE, system.DocumentsDirectory, CELLX, CELLY)

This corresponds with the new format of the newImage() call, but is undocumented (they’re fixing this). So, fortunately, we can uniformly use the new call format on both images and sprite sheets.

Meanwhile, the old call using system.pathForFile() no longer functions.

EDIT: Docs updated. [import]uid: 3953 topic_id: 6316 reply_id: 23353[/import]