使用打印后台处理程序 API 打印"raw"数据
Print "raw" data using Print Spooler API
我正在使用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
相关文章:
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 动态分配的聊天数组打印缺失的数据和空
- 访问和打印元组中的数据,并使用 C++14 使用模板函数显示数据
- C++ 打印包含数据结构的数组
- 从模板创建通用打印函数,以打印基元数据类型变量的值
- 在打印方法中,难以在二进制树中打印数据
- 面对迭代矢量<矢量<string>>和打印数据的问题
- 使用访问器以两种格式打印数据
- 如何在我从文件中读取的结构中打印数据
- 从 txt 文件中查找和打印数据
- 使用函数和数组从文件中读取和打印数据
- 通过C++从标准输出中的一些打印数据中提取特定值
- 以十六进制打印数据结构值
- 以正确的模式打印数据
- C++:打印数据,printf
- for_each打印数据不正确
- 在链表节点中递归打印数据,但使用多个前向链接C++(包括Pic)
- 在矢量中打印数据
- 在对话框中打印数据
- 打印数据QTextDocument和QPainter