作为项目的第一阶段,我一直在尝试打印出整个图像文件夹,但无法使其正常工作。这些图像被命名为“batch_X.jpg”(但如果效果更好,文件类型可以改变)并且为了测试,我只是将其打印为 pdf,以免浪费数千张纸。我可以让循环完成并将名为“testX”的文件放入输出文件夹,但是它们不是我要打印的图像,而是总是显示为空白页。
这是我一直在运行的代码,在所有地方都注释掉了行
QApplication app(int argc, char** argv());
for (int q = 1; q <= 11; q++)
{
//int q = 4;
QString fileName=QStringLiteral("/Users/user/Desktop/imageTests/output/batch_%1.jpg").arg(q);
// QPrinter printer;
//QPrintDialog *dlg = new QPrintDialog(&printer,0);
//if(dlg->exec() == QDialog::Accepted) {
QPrinter printer(QPrinter::ScreenResolution);
printer.setResolution(3000);
//printer.setPageLayout(page_layout);
printer.setCopyCount(1);
printer.setDoubleSidedPrinting(false);
printer.setDuplex(QPrinter::DuplexNone);
printer.setColorMode(QPrinter::Color);
printer.setPageSize(QPrinter::Letter);
printer.setPaperSize(QPrinter::Letter);
printer.setPaperSource(QPrinter::Auto);
//printer.setCreator("Inkjet Plumber");
printer.setOrientation(QPrinter::Portrait);
printer.setPageMargins(0.0, 0.0, 0.0, 0.0, QPrinter::Inch);
//printer.setPageLayout(page_layout);
QString outputFileName = QStringLiteral("/Users/user/Desktop/testing/test%1.pdf").arg(q);
printer.setOutputFileName(outputFileName);
printer.setOutputFormat(QPrinter::PdfFormat);
QImage img(fileName);
QPainter painter(&printer);
painter.drawImage(QPoint(0,0),img);
painter.end();
//QMessageBox::information(this, tr("Title"), QString(fileName));
}