[英]How to convert multi page Magick++ Image to QImage?
I convert Magick++ single page Image to QT image (QPixmap, actually, but could be QImage as well) with: 我将Magick ++单页图像转换为QT图像(实际上是QPixmap,但也可能是QImage),方法是:
Blob my_blob_1;
Image img1;
img1.magick("MNG"); // or PNG
img1.write(&my_blob_1);
const QByteArray imageData1((char*)(my_blob_1.data()),my_blob_1.length());
item1p.loadFromData(imageData1);
item1 = Scene->addPixmap(QPixmap(item1p));`
where: 哪里:
QPixmap item1p;
QGraphicsScene *Scene;
QGraphicsPixmapItem *item1;`
My question is: how could I do that with multi page Image? 我的问题是:如何处理多页图片? Below, I have a multipage image in a vector, I manipulate it with STL algorithms, but I can not find a way to output it to QT Image. 下面,我在矢量中有一个多页图像,我使用STL算法对其进行操作,但是找不到将其输出到QT Image的方法。 Magick++ writes it out to a single blob. Magick ++将其写到单个blob中。 I would need to write to separate blobs for each page. 我需要为每个页面写单独的Blob。 Do I, or is there other way? 我还是其他方法? vector to QVector 矢量到QVector
Blob my_blob_111;
vector<Image> imageListmpp;
writeImages( imageListmpp.begin(), imageListmpp.end(), &my_blob_111 );
Image aaa;
aaa.read(my_blob_111);
aaa.write( "D:/test/aaa.pdf" );`
I welcome any suggestion. 我欢迎任何建议。
Thanks! 谢谢!
Since you already have a vector of Magick Image
, your mistake was to save them all as a unique Blob
. 由于您已经有了Magick Image
的向量,因此您的错误是将它们全部保存为唯一的Blob
。 Instead, convert them individually to a blob, and then to a QPixmap
: 而是将它们分别转换为Blob,然后转换为QPixmap
:
vector<Image> imageListmpp; // your input
QVector<QPixmap> pixmaps; // your output (use std::vector if you prefer)
QVector<QGraphicsPixmapItem *> graphicsItems;
for(int i=0; i<imageListmpp.size(); i++)
{
// Get the individual image data
Blob blob;
imageListmpp[i].magick("MNG"); // or PNG
imageListmpp[i].write(&blob);
const QByteArray imageData((char*)(blob.data()),blob.length());
// Convert the data to a QPixmap in the vector
pixmaps << QPixmap();
pixmaps.last().loadFromData(imageData);
graphicsItems << Scene->addPixmap(pixmaps.last());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.