【问题标题】:Corona SDK getting error when loading image from the system.DocumentsDirectory从 system.DocumentsDirectory 加载图像时 Corona SDK 出现错误
【发布时间】:2014-01-31 00:57:11
【问题描述】:

我正在尝试从 system.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)

有什么帮助吗?

【问题讨论】:

    标签: lua coronasdk corona-storyboard corona-director


    【解决方案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 )
    

    【讨论】:

    • +1 但您可能应该解释原因:newImage 期望文件名与 baseDir 相关,baseDir 默认为 system.ResourceDir。在您的情况下,png位于文档文件夹中,因此您必须按照答案中显示的方式覆盖。感谢发帖。
    猜你喜欢
    • 1970-01-01
    • 2015-01-29
    • 2015-01-17
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多