使用打印后台处理程序 API 打印"raw"数据

Print "raw" data using Print Spooler API

本文关键字:打印 数据 raw API 处理 后台 程序      更新时间:2023-10-16

我正在使用Windows spooler API来打印简单的图片。在"文本"模式下,我的打印机将图片打印为文本,就像将其数据转换为字符一样。所以我必须使用"RAW"模式,但在这种情况下没有任何附加。
这是代码:

void camgl::printShoot() {
HANDLE print_handle;
DOC_INFO_1 docinfo1;
DWORD bytes_written;
docinfo1.pDocName = (LPTSTR)L"Shot.jpg";
docinfo1.pOutputFile = NULL;
docinfo1.pDatatype = (LPTSTR)L"RAW";
BOOL bool1, bool2, bool3, bool4;
bool1 = OpenPrinter((LPTSTR)L"Canon MG6300 series Printer", &print_handle, NULL);
bool2 = StartDocPrinter(print_handle, 1, (LPBYTE)&docinfo1);
bool3 = StartPagePrinter(print_handle);
bool4 = WritePrinter(print_handle, (LPVOID)image->imageData, (DWORD)image->imageSize, &bytes_written);
EndPagePrinter(print_handle);
EndDocPrinter(print_handle);
ClosePrinter(print_handle); 
}

变量"image"的定义如下:

    图像
  • *图像;

其中 IplImage 是 OpenCV 类型的图像。

我尝试将表单馈送字符发送到打印机,但没有成功:

int iFF = 0x0c;
WritePrinter(print_handle, (LPVOID)&iFF, (DWORD)sizeof(iFF), &bytes_written);

在这两种情况下,打印队列都会显示与 printShoot() 方法对应的作业,然后清除队列,没有错误,打印机也不会打印任何内容。

====

==========我

添加我刚刚发现的这篇文章:
http://www.codeproject.com/Articles/8916/Printing-Architecture

WritePrinter 仅支持 GDI 打印。

打印 JPEG 图像需要更多的代码。如果紧急,可以尝试调用命令行MS 画图打印 JPEG 图像

C:WindowsSystem32mspaint.exe C:image.jpg /p

我通过使用XPS API找到了解决方案,如前所述:
http://msdn.microsoft.com/en-us/library/windows/desktop/ff728890(v=vs.85).aspx

那里有一个示例代码:
http://msdn.microsoft.com/en-us/library/windows/desktop/ee236514(v=vs.85).aspx