CPCL命令打印24位bmp
来源:互联网 发布:js md5算法 编辑:程序博客网 时间:2024/06/12 00:18
看到很多朋友跟我遇到相似的问题,我把我当初的解决办法贴出来吧。下面的代码是读取24位bmp文件的方法(距离写这个代码有一段时间了,有些注释掉的代码已经忘了干嘛的了)
private static string get24BitBmpData(string filePath){ Bitmap bmp = new Bitmap(filePath); byte[] bitArray = { 128, 64, 32, 16, 8, 4, 2, 1 }; string imgTxt = ""; Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData data = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); IntPtr firstPix = data.Scan0; int rowByteCount = bmp.Width * 3; int filledCount = data.Stride - rowByteCount; int bytes = data.Stride * data.Height;//Math.Ceiling((double)bmp.Width / 8) byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(firstPix, rgbValues, 0, bytes); int printRowByteCount = Convert.ToInt32(Math.Ceiling((double)(bmp.Width) / 8)); int printRowByteFillCount = 4 - (printRowByteCount % 4); //int bitFillCount = 8 - (bmp.Width % 8); byte[] printData = new byte[(printRowByteCount + printRowByteFillCount) * bmp.Height]; int byteCount = 0; int bitCount = 0; int rowPoint = 0; for (int i = 0; i < rgbValues.Length; i += 3) { int rgbValue = rgbValues[i] + rgbValues[i + 1] + rgbValues[i + 2]; if (rgbValue != (255 * 3)) { printData[byteCount] = Convert.ToByte(printData[byteCount] | bitArray[bitCount]); } if (bitCount == 7) { bitCount = 0; byteCount++; } else { bitCount++; } if ((rowPoint + 3) == rowByteCount) { rowPoint = 0; if (bitCount > 0) { byteCount++; } bitCount = 0; byteCount += printRowByteFillCount; //if (bitCount + filledCount <= 7) //{ // bitCount += filledCount; //} //else //{ // bitCount = filledCount - 8 + bitCount; // byteCount++; //} i = i + filledCount; } else { rowPoint += 3; } } foreach (byte byteData in printData) { string hexStr = Convert.ToString(byteData, 16); if (hexStr.Length == 1) { hexStr = '0' + hexStr; } imgTxt += hexStr; } bmp.UnlockBits(data); return imgTxt.ToUpper();}
string CRNL = "\r\n";
string imgTxt = get24BitBmpData("xxxx.bmp");
string cmddata = "! 0 200 200 300 1" + CRNL +
"EG " + 24 + " " + 50 + " 10 10 " + imgTxt + CRNL +
"FORM" + CRNL +
"PRINT" + CRNL;
- CPCL命令打印24位bmp
- 24位BMP转8位BMP
- 将32位BMP文件转换为24位BMP
- 32位bmp图转24位bmp图
- 24位bmp剪切并转存为单色bmp
- 利用24位BMP位图进行加密
- c++读取BMP文件(24位)
- 32为bmp转换成24位
- 24位BMP文件存储介绍
- 24位bmp图像转成灰度图像
- 24位bmp的存储方式
- Iplimage转BMP(24位)
- SDL2解析并显示24位bmp
- 24位位图转4位彩色图(BMP)
- BMP的8位位图转换24位位图
- BMP图像的处理(24位转16位)
- 24位深,16位深 BMP 图片解析
- 2 4 8位BMP转24位BMP(代码)
- 如何判断fork之后的子进程是否已经结束
- 关于视图的更新问题
- ListView有背景图片或背景颜色,那么在滑动ListView的时候,ListView的背景会变黑
- MFC生成GUID
- 是否处于设计状态(处于VS设计界面)
- CPCL命令打印24位bmp
- Eclipse快捷键大全(转载)
- 如何修改TortoiseSVN的Log日志
- sql取两位小数
- 启发式搜索
- 浅谈VS安装部署
- ling to xml 实现 增删改查 功能
- 学习!
- 进程间通信--共享内存