问题描述
我喜欢在HTML5中,您可以将文本数据保存到本地数据库,甚至可以使用SQL来完成。 ()
I love that in HTML5 you can save text data out to a local database, and can even use SQL to do it. (http://webkit.org/blog/126/webkit-does-html5-client-side-database-storage/)
我有一个应用程序, MObile Safari,它缓存一切离线,除了图像。图像仍然必须从服务器下载,我不知道如何确保他们将保持缓存。理想情况下,我想把它们写到localStorage数据库中。
I've got an app that I've written for the iPhone's MObile Safari that caches everything offline except for images. The images still have to be downloaded from the server, and I don't know how to ensure that they will stay cached. Ideally, I'd like to write them out to the localStorage database.
我想把图像写到画布上,然后把它作为文本序列化...有任何想法吗?有没有更简单的方法来做到这一点?
I was thinking of writing an image to the canvas, and then serializing that as text... any ideas? Is there any easier way to do this?
理想情况下,我想用HTML和JavaScript,没有本机应用程序/目标C。 >
Ideally, I'd like to do this all with HTML and JavaScript, no native apps/objective-C.
推荐答案
查看html5中的应用程序缓存,这基本上是你想要的(它也是你想要使用的,如果你想支持完全离线的网络应用程序)。
Look at the application cache in html5, that does basically exactly what you want (it's also what you want to use if you want to support completely offline web applications).
或者,你可以(有点丑陋)将图像拖到画布上,然后到canvas.toDataURL()获取图像的数据网址,然后您可以将其存储在正常数据库或脱机存储apis中。
Alternatively you could (somewhat ugly)daw the image to canvas, then to canvas.toDataURL() to get a data url for the image, which you can then store in the normal database or offline storage apis.
这篇关于在HTML5中,您可以通过编程方式保存图片吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!