# Xiaoyifang/goldendict 加载图片词典比较慢，不知能否优化？

**URL:** <https://forum.freemdict.com/t/topic/23713>\
**Category:** 软件经验交流展望\
**Tags:** goldendict\
**Created:** [2023 年9 月 29 日 11:52 UTC](https://forum.freemdict.com/t/topic/23713 "2023-09-29T11:52:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2023 年9 月 29 日 11:52 UTC](https://forum.freemdict.com/t/topic/23713/1 "2023-09-29T11:52:15Z")

</div>

最近制作了一个图片词典，但有个问题困扰了我两天：整个词典1000多页，但其中有且仅有一页，只要打开它的链接，[官版goldendict](https://github.com/goldendict/goldendict)程序就崩溃，即使我将该页面的图片重新制作或更换为其他没有问题的图片，问题虽有些变化但依然存在（程序不崩溃，但图片无法加载等），为此我下载了[xiaoyifang/goldendict](https://github.com/xiaoyifang/goldendict/)的windows portable版本（5.15.2-GoldenDict.exe\_windows-2019\_20230910.zip，6.5.2-GoldenDict.exe\_windows-2019\_20230910.zip），好的方面是打开上述词典完全正常，但糟糕的是其加载图片的速度明显不如官版，就好像十多年前加载网页一样逐渐显示出来。

不知是我没有正确设置，还是有其他更好的优化方案？

就是这一页导致官版goldendict总是崩溃：

 ![image](https://forumcdn.freemdict.com/uploads/default/original/3X/8/e/8ed8d373f701314e28e81a57688a35d13caa6cc0.jpeg)

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年9 月 29 日 12:05 UTC](https://forum.freemdict.com/t/topic/23713/2 "2023-09-29T12:05:09Z")

</div>

你把这一张图片，单独做成mdx + mdd，试试可不可以复现，如果可以复现的话，发出来看看。

---

<div class="post-metadata">

作者： ![random](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/random/32/19006_2.png) [@random](https://forum.freemdict.com/u/random)\
发布日期： [2023 年9 月 29 日 12:48 UTC](https://forum.freemdict.com/t/topic/23713/3 "2023-09-29T12:48:59Z")

</div>

你不说我还没注意到，-ng版确实加载图片很慢

---

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2023 年9 月 29 日 13:35 UTC](https://forum.freemdict.com/t/topic/23713/4 "2023-09-29T13:35:49Z")

</div>

好建议，我使用官版goldendict 1.5版对以下材料做了试验，结果很神奇：

[OPEU4th test.zip](https://forum.freemdict.com/uploads/short-url/5A864Txbj7mkahNGHTzuiwuZtaq.zip) (4.2 MB)  
其中，源文件仅有前文所述的问题页面，而图片有前后页共4张。

试验内容仅增减图片，然后用mdxbuilder重新输出mdx和mdd，其他都保持不变。

- 如果图片只有OPEU4\_0002.png，那么访问OPEU4\_0002，一切正常。
- 如果图片有OPEU4\_0001.png、OPEU4\_0002.png，那么访问OPEU4\_0002，可以加载页面，但图片处是个问号，无法加载。
- 如果图片有OPEU4\_0001.png、OPEU4\_0002.png、OPEU4\_0003.png，那么访问OPEU4\_0002，程序旋转半天类似死机，之后自动关闭程序。
- 如果图片有OPEU4\_0001.png、OPEU4\_0002.png、OPEU4\_0003.png、OPEU4\_0004.png，那么访问OPEU4\_0002，程序快速崩溃退出。

---

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2023 年9 月 29 日 13:44 UTC](https://forum.freemdict.com/t/topic/23713/5 "2023-09-29T13:44:32Z")

</div>

可能我又遇到曾经的经历了，ComicEnhancerPro输出的图片，偶尔会使官版goldendict崩溃。

我将上述图片重新使用PS/导出/快速导出为PNG-8/覆盖原文件，一切就正常了。

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年9 月 29 日 13:56 UTC](https://forum.freemdict.com/t/topic/23713/6 "2023-09-29T13:56:22Z")

</div>

图片加载慢，你自己看下开发者工具里的对应图片的响应加载渲染时间。看看是慢在哪个环节，如果是响应慢，找 xiaoyifang，如果是加载渲染慢，那没辙，这个是浏览器问题。

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年9 月 29 日 14:15 UTC](https://forum.freemdict.com/t/topic/23713/7 "2023-09-29T14:15:29Z")

</div>

这个不是图片本身的问题，论坛里两三年前就讨论过了，结论是把下面第 622 行的 `endPos` 改成 `shadowEndPos` 就可以了。

> <https://github.com/goldendict/goldendict/blob/master/mdictparser.cc#L622>

> <https://github.com/xiaoyifang/goldendict-ng/blob/staged/src/dict/mdictparser.cc#L559>

---

<div class="post-metadata">

作者： ![random](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/random/32/19006_2.png) [@random](https://forum.freemdict.com/u/random)\
发布日期： [2023 年9 月 29 日 14:43 UTC](https://forum.freemdict.com/t/topic/23713/8 "2023-09-29T14:43:46Z")

</div>

![image](https://forumcdn.freemdict.com/uploads/default/original/3X/0/4/04ba429c439793dcb6580312eb2116514dabfdcc.png)  
不知道是不是正常的

图片有个从模糊到清晰的过程。

p.s. 我给图片加上了绝对定位的文字层，可能也跟这个有关。

---

<div class="post-metadata">

作者： ![匿名1475](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E5%8C%BF%E5%90%8D1475/32/51086_2.png) [@匿名1475](https://forum.freemdict.com/u/%E5%8C%BF%E5%90%8D1475)\
发布日期： [2023 年9 月 29 日 15:04 UTC](https://forum.freemdict.com/t/topic/23713/9 "2023-09-29T15:04:02Z")

</div>

Vim 兄，在下也曾多次出现类似问题，后来发现改图号编码就没问题了，如 OPEU4\_0002.png，最好改成OPEU\_0002.png，也就是编码在\_的左端最后都不要有数字，您不妨试试，是否也能解决

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年9 月 29 日 15:11 UTC](https://forum.freemdict.com/t/topic/23713/10 "2023-09-29T15:11:57Z")

</div>

没有什么用，图片很少的时候可改顺序，图片多的话，这张图片没问题了，其他图片也会加载失败。  
这个是GoldenDict代码本身的问题。

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年9 月 29 日 15:20 UTC](https://forum.freemdict.com/t/topic/23713/11 "2023-09-29T15:20:38Z")

</div>

我测试了一本带绝对定位的文字+图片版，NG 耗时确实比官方的长很多，重新测试，去掉定位的文本和样式就正常了，应该是浏览器本身的差异。

---

<div class="post-metadata">

作者： ![匿名1475](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E5%8C%BF%E5%90%8D1475/32/51086_2.png) [@匿名1475](https://forum.freemdict.com/u/%E5%8C%BF%E5%90%8D1475)\
发布日期： [2023 年9 月 29 日 15:21 UTC](https://forum.freemdict.com/t/topic/23713/12 "2023-09-29T15:21:51Z")

</div>

在下试过这样的编码原则没有出过问题，甚至3000 - 4000 张图片打包在一个mdd也是正常的，以往的编码也有像 OPEU4\_0001.png ，OPEU4\_0002.png …，所出现的问题常常是单页图号可加载，双页图号的出不来  
若担心图片多也可打成多几个包，这样应该是可以减轻负载

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年9 月 29 日 15:24 UTC](https://forum.freemdict.com/t/topic/23713/13 "2023-09-29T15:24:47Z")

</div>

你这样属于碰运气，这个是软件的问题。

---

<div class="post-metadata">

作者： ![匿名1475](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E5%8C%BF%E5%90%8D1475/32/51086_2.png) [@匿名1475](https://forum.freemdict.com/u/%E5%8C%BF%E5%90%8D1475)\
发布日期： [2023 年9 月 29 日 15:32 UTC](https://forum.freemdict.com/t/topic/23713/14 "2023-09-29T15:32:02Z")

</div>

情况可能如您所说的，但此法也解决了碰到的问题，能解决这么多次也算值得 😆

---

<div class="post-metadata">

作者： ![xiaoyifang](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/x/df788c/32.png) [@xiaoyifang](https://forum.freemdict.com/u/xiaoyifang)\
发布日期： [2023 年9 月 30 日 02:16 UTC](https://forum.freemdict.com/t/topic/23713/15 "2023-09-30T02:16:17Z")

</div>

看图片的尺寸是 3000x5000的。  
显示图片的时候，css限定 48em。 是否可以缩小下图片尺寸，看下。

---

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2023 年9 月 30 日 23:14 UTC](https://forum.freemdict.com/t/topic/23713/16 "2023-09-30T23:14:27Z")

</div>

> [@last\_idol](#):
>
> 结论是把下面第 622 行的 `endPos` 改成 `shadowEndPos` 就可以了。

已反馈至官版，并有人修正了这个错误：

> <https://github.com/goldendict/goldendict/pull/1673>
>
> See the commit messages for details.
> 
> Fixes #1672

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 02:41 UTC](https://forum.freemdict.com/t/topic/23713/17 "2023-10-01T02:41:55Z")

</div>

就是按上面说的修的，应该没问题了。

---

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2023 年10 月 1 日 03:02 UTC](https://forum.freemdict.com/t/topic/23713/18 "2023-10-01T03:02:06Z")

</div>

> [@last\_idol](#):
>
> 就是按上面说的修的，应该没问题了。

是的，感谢。

俄罗斯论坛已发出包含该更新的最新编译版了，大家下载后直接覆盖官版的1.5版即可：

[1.5.0-10-ga14374dc](https://www.mediafire.com/file/ioh86ngpn3y9ra9/goldendict-1.5.0-10-ga14374dc%2528EXE_only%2529.7z/file)

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2023 年10 月 1 日 03:11 UTC](https://forum.freemdict.com/t/topic/23713/19 "2023-10-01T03:11:49Z")

</div>

GoldenDict 加载图片应该跟 QT 版本有关， xiaoyifang 的 GoldenDict 用 QT5 版的加载速度会好些

加载速度最快应该还是 mdict，因为最古老（代价是呈现的图片质量会下滑）

---

<div class="post-metadata">

作者： ![last\_idol](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/last_idol/32/2205_2.png) [@last\_idol](https://forum.freemdict.com/u/last_idol)\
发布日期： [2023 年10 月 1 日 03:52 UTC](https://forum.freemdict.com/t/topic/23713/20 "2023-10-01T03:52:22Z")

</div>

不知道你们加载图片是什么情况，以上面 vim 的词典为例，加载图片80ms，最大内容渲染lcp是284ms。考虑是3000x5000的图片，这两指标已经很好了。

[下一页](https://forum.freemdict.com/t/topic/23713.md?page=2)
