我的程序使用复杂的规则创建图像,然后将其显示在 QScrollArea 中。目前我这样做:
- 创建 QImage
- 使用 QImage::setPixel 填充它
- 添加我的小部件(从 QWidget 派生)到 QScrollArea
- 在小部件中定义 PaintEvent 并使用 QPainter::drawImage
这是显示生成图像的最简单方法吗?
现在我有一个问题。图像可能非常大。 QImage将数据存储在内存中,不能存储大图像。我想将生成的图像存储在磁盘上,并以任何缩放快速绘制它的任何部分。我该怎么做?
My program creates an image using complicated rules, then displays it in QScrollArea. Currently I do it this way:
- create QImage
- fill it using QImage::setPixel
- add my widget (derived from QWidget) into QScrollArea
- define paintEvent in widget and use QPainter::drawImage
Is it simpliest way to display generated image?
Now I have a problem. The image can be very large. QImage stores data in memory and can't store big images. I want to store generated image on disk and draw any part of it with any zoom fastly. How can I do this?
发布评论
评论(2)
您可能想查看这篇文章,描述 QPixmap 和 QImage 之间的一些差异:
http://techbase.kde.org/Development/Tutorials/Graphics/Performance#QPixmap_vs._QImage
如果您想快速缩放非常大的图像,有一种方法可以实现,称为“深度缩放”和“可缩放用户界面”(ZUI):
http://en.wikipedia.org/wiki/Deep_Zoom
QScrollArea
并不是为了开箱即用而设计的。我不了解 Qt 实现,但我个人使用过一个名为 OpenZoom 的开源 Flash。您可以看到我的结果:http://hostilefork.com/2010/ 09/12/imagination-squared-plus-openzoom/
很高兴看到有人以可重用的 Qt 方式解决这个问题。
You probably want to check into this article describing some of the differences between
QPixmap
andQImage
:http://techbase.kde.org/Development/Tutorials/Graphics/Performance#QPixmap_vs._QImage
If you want to zoom very large images fast, there is a methodology for that, called "Deep Zooming" and "Zoomable User Interfaces" (ZUI):
http://en.wikipedia.org/wiki/Deep_Zoom
QScrollArea
is not designed to do this out of the box. I don't know about Qt implementations, but personally I played with an open-source Flash one called OpenZoom. You can see my results:http://hostilefork.com/2010/09/12/imagination-squared-plus-openzoom/
It would be nice to see someone tackling this in a reusable fashion for Qt.
显示生成图像的最简单方法是将其分配给 QLabel。使用
QLabel::SetPixmap()
而不是您自己的小部件。我将如何完成该任务...
首先,创建许多尺寸足够好的单独图像(1024x1024,甚至更小)。
之后制作该图像的矩阵。您可以将其图像一一读取并写入文件。如果您需要显示图像的某些部分 - 只需从文件中读取所需的图像。
要在文件中定位,请使用简单的查找表,其中包含
xId yId offset length
等字段要快速使用缩放 - 只需添加更多矩阵 - 下一个矩阵应该比基数小两倍,依此类推,直到您剩下单个图像(对于最远的缩放)。
the simpliest way to display generated image would be assigning it to QLabel. Use
QLabel::SetPixmap()
instead of your own widget.How would I do that task...
First, create many separate images with the good enough size (1024x1024, or even smaller).
After that make a matrix of that images. you may read and write its images to file one-by-one. if you need to display some part of your image - just read needed images from file.
for positioning in file use simple lookup table, with fields like
xId yId offset length
To work with zoom fast - just add more matrixes - next one should be two times smaller then base, and so on, until you has single image left(for the most far zoom).