如何缓存base64编码图片

How to cache base64 encode image

您好,我正在使用 angular.jsphp 开发小型学校应用程序,从 canvas 然后将其存储在 mySql db 中。

图像已存储 image/pngbase64 string

我的问题是,当我加载这些图像(300 张 11.2Kb 的图像)时,需要很长时间才能在屏幕上显示它(3Mb 大约需要 1 分钟 HTML).

是否有任何库或 angular 指令可用于在显示时缓存这些图像?

嗯,首先,在数据库中存储图像是quite a bad practice。我建议您将图像保存为二进制文件并存储上传路径。

其次,以 base64 格式存储大图像会占用更多内存(base64 图像通常比二进制文件大 ~33%),并且 claimed here,渲染它们可能会花费更多时间。

base64 encoded data may possibly take longer to process than binary data (again, this might be exceptionally painful for mobile devices, which have more limited CPU and memory)

顺便说一句,如果我误解了你,瓶颈是从数据库中读取图像,那么将图像存储为文件也会有所帮助;)