简体   繁体   English

Appcelerator图片未保存

[英]Appcelerator images not being saved

TiSDK 1.7.1 TiSDK 1.7.1
iOS 5.0 iOS 5.0

I'm attempting to take the URL of an image that is passed to the app and store it in applicationDataDirectory. 我正在尝试获取传递给应用程序的图像的URL,并将其存储在applicationDataDirectory中。

I've written a function that takes the url, creates an ImageView, passes it to .toImage() and then writes it to a file. 我编写了一个函数,该函数采用url,创建ImageView,将其传递给.toImage(),然后将其写入文件。

http://pastie.org/3064770 http://pastie.org/3064770

When I run it in the simulator and go to the applicationDataDirectory in finder to view the image it's the generic placeholder image that is stored, not the image that is being passed. 当我在模拟器中运行它并转到finder中的applicationDataDirectory来查看图像时,它是存储的通用占位符图像,而不是正在传递的图像。

Thoughts? 有什么想法吗?

I think the problem is you are saving the image when the image has not downloaded from the web yet - it has no data. 我认为问题在于,当您尚未从网络上下载图像时,您正在保存图像-它没有数据。 The image is not available as soon as you get the image property - you have to wait for the 'load' event. 获得图像属性后,该图像将立即不可用-您必须等待'load'事件。 Dawson Toth has a great example on how to create a caching image view which saves the file when the image has loaded . Dawson Toth有一个很好的示例,说明如何创建缓存图像视图,该视图在图像加载后保存文件 iOS only as the 'load' event doesn't fire in Android in 1.7.X. 仅限iOS,因为1.7.X中的'load'事件不会在Android中触发。

Also, Titanium will only load the image when it is displayed on the screen. 此外,Titanium仅在屏幕上显示图像时才加载图像。 So if you want to download it in the background, use a HttpClient . 因此,如果要在后台下载,请使用HttpClient

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM