2014-01-31 60 views
0

我想從system.DocumentsDirectory中加載圖像,但是我收到了此錯誤消息。Corona SDK從系統加載圖像時出現錯誤.DocumentsDirectory

WARNING: Failed to find image(C:\Users\beri\AppData\Roaming\Corona Labs\Corona S 
imulator\Sandbox\jet shooter - pro-B1C630B0B5247780928E75EA15C69ABF\Documents\cu 
stomJet.png) 

我正在使用此代碼來創建圖像並再次顯示,但我收到錯誤消息說圖像不存在。

-- Creating the image 
local screenBounds = 
{ 
    xMin = 0, 
    xMax = 800, 
    yMin = 116.5, 
    yMax = 360, 
} 
local customJet = display.captureBounds(screenBounds) 
local baseDir = system.DocumentsDirectory; 
display.save(customJet, "customJet.png", baseDir) 

-- Loading the image 
local path = system.pathForFile("customJet.png", system.DocumentsDirectory) 
local jetOne = display.newImage(path) 

任何幫助?

回答

1
-- Creating the image 
local screenBounds = 
{ 
    xMin = 0, 
    xMax = 800, 
    yMin = 116.5, 
    yMax = 360, 
} 
local customJet = display.captureBounds(screenBounds) 
local baseDir = system.DocumentsDirectory; 
display.save(customJet, "customJet.png", baseDir) 

-- Loading the image 
local jetOne = display.newImage("customJet.png", system.DocumentsDirectory) 
+0

+1但你應該解釋爲什麼:newImage期望文件名與baseDir相關,baseDir的默認值是system.ResourceDir。在你的情況下,PNG是在文檔文件夾,所以你必須覆蓋,因爲你在你的答案中顯示。感謝發佈。 – Schollii