Appcelerator 图像未保存

发布于 2024-12-22 20:13:07 字数 374 浏览 2 评论 0原文

TiSDK 1.7.1
iOS 5.0

我试图获取传递到应用程序的图像的 URL 并将其存储在 applicationDataDirectory 中。

我编写了一个函数,它接受 url,创建 ImageView,将其传递给 .toImage(),然后将其写入文件。

http://pastie.org/3064770

当我在模拟器中运行它并进入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.

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.

Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ人海孤独症 2024-12-29 20:13:07

我认为问题是当图像尚未从网络下载时您正在保存图像 - 它没有数据。获得图像属性后,图像不可用 - 您必须等待“加载”事件。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文