我想做一些图像矩阵,在一些小工具中显示预览,并在所有保存到-例如- jpg文件。我知道我可以将每个像素的图像复制到一个大的像素中,但我想这不是一个有效的方法……有没有更好的解决方案?
谢谢你的建议。
发布于 2011-06-25 21:36:08
我不会复制单独的像素,而是直接在足够大的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。
发布于 2011-06-25 21:36:43
不,你不会想一个像素一个像素地做的。QImage是一个QPaintDevice。因此,您可以加载它们,将它们相互渲染,并将它们保存为您喜欢的几种格式。当然也会把它们显示在屏幕上。
发布于 2012-09-21 22:28:37
上面的代码对我不起作用,我不知道为什么。
我需要的是像这样的拼贴画:
PicA | PicB | Pic...| ... |
我在QImage中发现了一些类似的东西,并且这段代码可以工作。
(测试代码):
const int S_iconSize = 80; //The pictures are all quadratic.
QList<const QPixmap*> t_images;//list with all the Pictures, PicA, PicB, Pic...
QImage resultImage(S_iconSize*t_images.size(), S_iconSize, QImage::Format_ARGB32_Premultiplied);
QPainter painter;
painter.begin(&resultImage);
for(int i=0; i < t_images.size(); ++i)
{
painter.drawImage(S_iconSize*i, 0, t_images.at(i)->toImage(), 0, 0, S_iconSize, S_iconSize, Qt::AutoColor);
}
painter.end();
QPixmap resultingCollagePixmap = QPixmap::fromImage(resultImage);我知道这很难看,因为QImage被转换为QPixmap,反之亦然,但它是有效的。因此,如果有人知道如何让上面的代码(来自Ton van den Heuvel)运行,我会很高兴。(可能只是一个丢失的QPainter?)
问候
https://stackoverflow.com/questions/6477958
复制相似问题