Appcelerator 图像未保存
TiSDK 1.7.1
iOS 5.0
我试图获取传递到应用程序的图像的 URL 并将其存储在 applicationDataDirectory 中。
我编写了一个函数,它接受 url,创建 ImageView,将其传递给 .toImage(),然后将其写入文件。
当我在模拟器中运行它并进入finder中的applicationDataDirectory查看时图像是存储的通用占位符图像,而不是正在传递的图像。
想法?
TiSDK 1.7.1
iOS 5.0
I'm attempting to take the URL of an image that is passed to the app and store it in applicationDataDirectory.
I've written a function that takes the url, creates an ImageView, passes it to .toImage() and then writes it to a file.
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.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是当图像尚未从网络下载时您正在保存图像 - 它没有数据。获得图像属性后,图像不可用 - 您必须等待“加载”事件。 Dawson Toth 有一个关于如何创建缓存图像视图的很好的示例,该视图在图像加载时保存文件 。仅适用于 iOS,因为 Android 1.7.X 中不会触发“load”事件。
此外,Titanium 仅在图像显示在屏幕上时才加载图像。因此,如果您想在后台下载它,<a href="http://kevin.h-pk-ns.com/2011/03/11/image-views-in-titanium-how-to-deal- with-caching/" rel="nofollow">使用 HttpClient。
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. Dawson Toth has a great example on how to create a caching image view which saves the file when the image has loaded. iOS only as the 'load' event doesn't fire in Android in 1.7.X.
Also, Titanium will only load the image when it is displayed on the screen. So if you want to download it in the background, use a HttpClient.