Q图像文件路径
我在任何地方的文档中都没有看到这一点,所以它可能不存在,但以防万一:
我有一个函数接受 QImages 向量作为参数。每个 QImage 都是在某个时刻从磁盘加载的,并且没有被编辑——它只是被读取。理想情况下,我想做的是循环所有 QImage 并将其文件路径列表输出到 XML 文件。
不幸的是,我在文档中没有看到任何方法来获取加载图像的原始文件路径。所以我的问题是,仅给定一个 QImage,是否有可能找出 QImage 最初从哪个文件路径加载?
类似于:
QString QImage::getOriginalFilepath();
我知道这可能是一个徒劳的问题,但我想它总是值得一试。
(顺便说一句,我正在使用 Qt 4.7。)
I don't see this in the documentation anywhere, so it probably doesn't exist, but just in case:
I have a function that accepts as a parameter a vector of QImages. Each QImage was loaded from disk at some point and has not been edited--it is just read from. Ideally what I'd like to do is loop over all the QImages and output a list of their file paths to an XML file.
Unfortunately, I'm not seeing in the documentation any way to get at the original file path that the image was loaded from. So my question is, is it possible, given only a QImage, to figure out what file path the QImage was originally loaded from or not?
Something along the lines of:
QString QImage::getOriginalFilepath();
I know this is probably a futile question, but its always worth a shot to ask, I suppose.
(I'm using Qt 4.7, by the way.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我查看了代码,该信息似乎没有保存在任何地方。 QImage::load(和构造函数)使用 QImageReader(fileName,format).read() ,然后将结果复制到自身。 QImageReader 设置为在完成读取后立即删除设备表示(打开的文件对象)。
所以,综上所述,这似乎是不可能的。
I looked through the code, and that information doesn't appear to be saved anywhere. QImage::load (and the constructor) uses QImageReader(fileName,format).read() and then copies the result to itself. The QImageReader is set to delete the device representation (the opened file object) as soon as it's finished reading.
So, in summary, it appears that this is not possible.
另外对我来说,QImage 似乎没有提供获取其路径的接口。我还认为这不是一个缺失的功能,因为不需要将 QImage 绑定到特定路径。在大多数用例中,QImage 没有相应的物理文件。
因此,在您的情况下,最好的方法是子类化 QImage 并添加此功能:
我省略了实现细节。
Also for me it seems that QImage doesn't provide an interface to get its path. I also think that this is not a missing feature, because there's no need to tie a QImage to a specific path. In the majority of all use cases the QImage has no corresponding physical file.
So the best way in your situation would be to subclass QImage and add this feature:
I omit the implementation details.
我通常创建一个结构来保存 QImage 和图像路径。
I usually create a struct for hold the QImage and the image path.