Win10 - Can't load C:\test.png
Monkey Targets Forums/Desktop/Win10 - Can't load C:\test.png
| ||
| I want to load external images into my app using RequestFile. On Windows 10 this doesn't work. So I made a sample app, trying to load an image located at C:\ It's not working. But on Mac OS X I can load files from anywhere. So what's wrong here? Import mojo2
Class MyApp Extends App
Field canvas: Canvas
Field img: Image
Method OnCreate()
SetUpdateRate 60
canvas = New Canvas
img = Image.Load("C:\test.png")
End
Method OnRender()
canvas.Clear 0,0,1
If img Then
canvas.DrawImage(img, MouseX, MouseY)
End
canvas.Flush
End
End
Function Main()
New MyApp
End |
| ||
| After testing and reading this I suspected it wasn't possible. http://www.monkey-x.com/docs/html/Programming_Resource%20paths.html But then checking modules/mjo/data.monkey it turns out there is a special check for :/ so this code does work for me:
img = Image.Load("C:/spam.png")
|
| ||
| Ratchet's code fails on 7 here, but that forward-slash path does indeed work. Weird! |
| ||
| The problem is under Windows RequestFile gives you path with \ In mojo2/graphics.monkey the function KludgePath don't hande path with \ only with / This will cause your path from Request file ends up in "monkey://C:\test.png" I modified KludgePath like this and it works anytime: Function KludgePath:String( path:String )
Local i: Int
If path.StartsWith( "." ) Or path.StartsWith( "/" ) Return path
i=path.Find( ":\\" )
If i<>-1 Then Return path
i = path.Find( ":/" )
If i<>-1 And path.Find("/")=i+1 Return path
Return "monkey://data/"+path
End |