我想做一些图像矩阵,在一些小部件中显示预览,然后将其保存到 - 例如 - jpg
文件。我知道我可以将每个像素的每个图像像素复制到大图像中,但我认为这不是有效的方法......有没有更好的解决方案?
谢谢你的建议。
最佳答案
我不会复制单个像素,而是直接在 QPixmap
上直接绘制每个单独的图像,该图像足够大以容纳所有图像。然后可以通过在拼贴画上绘制每个单独的图像来生成拼贴画,如下所示(未经测试的代码):
QList<QPixmap> images;
QPixmap collage;
// Make sure to resize collage to be able to fit all images.
...
for (QList<QPixmap>::const_iterator it = images.begin(); it != images.end(); ++it)
{
int x = 0;
int y = 0;
// Calculate x & y coordinates for the current image in the collage.
...
QPainter painter(&collage);
painter.drawPixmap(
QRectF(x, y, (*it).width(), (*it).height()), *it,
QRectF(0, 0, (*it).width(), (*it).height()));
}
请注意,QImage
也可以用来代替 QPixmap
。 QPixmap
针对屏幕显示进行了优化。查看Qt documentation了解更多详情。
关于c++ - QT - 是否有将几张图片组合成一张的类(class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6477958/