从标题中你可以看到,这个问题已在过去讨论过了。我已将之前的帖子作为参考,并尝试在Zebra标签打印机上打印位图图像。我无法打印我要查找的图像。请不要忽视它的讨论。
请查看下面提到的代码段:
private string TestImage()
{
string filepath = Application.StartupPath + "\\ImageSymbols\\CSA.bmp";
byte[] bitmapFileData = System.IO.File.ReadAllBytes(filepath);
int fileSize = bitmapFileData.Length;
// Retrieve the image.
Bitmap image1 = new Bitmap(filepath, true);
//Siva - Not in use
Rectangle rect1 = new Rectangle(0, 0, image1.Width, image1.Height);
System.Drawing.Imaging.BitmapData bmpData1 =
image1.LockBits(rect1, System.Drawing.Imaging.ImageLockMode.ReadWrite,
image1.PixelFormat);
//Gets the height and width of the bitmap file
int bitmapDataHeight = image1.Height;
int bitmapDataWidth = image1.Width;
//Gets the size of the bitmap file
long bitmapDataFileSize = new FileInfo(filepath).Length;
//Gets the size of the bitmap file in integer
int bitmapDataFileSizeInt = Convert.ToInt32(bitmapDataFileSize);
//Gets the bitmap offset data in bytes.
byte[] test = bitmapFileData.Skip(10).Take(1).ToArray();
//assigns the bitmap offset data to a array value
byte bitmapDataOffset = test[0]; // i am getting offset value = 62
//changes the bitmap offset data to a integer value
int bitmapDataOffsetInt = Convert.ToInt32(bitmapDataOffset);
//gets the bitmap data file size by subtracting the file size with the bitmap offset data size
int bitmapDataSize = bitmapDataFileSizeInt - bitmapDataOffset;
//int width = 80;
//int height = 80;
int bitsPerPixel = 1; // Monochrome image required!
//int bitmapDataLength = 8160;
double widthInBytes = Math.Ceiling(bitmapDataWidth / 8.0);
// Copy over the actual bitmap data from the bitmap file.
// This represents the bitmap data without the header information.
byte[] bitmap = new byte[bitmapDataSize];
//bmpData1
Buffer.BlockCopy(bitmapFileData, bitmapDataOffset, bitmap, 0, bitmapDataSize);
// Invert bitmap colors
for (int i = 0; i < bitmapDataSize; i++)
{
bitmap[i] ^= 0xFF;
}
// Create ASCII ZPL string of hexadecimal bitmap data
string ZPLImageDataString = BitConverter.ToString(bitmapFileData);
ZPLImageDataString = ZPLImageDataString.Replace("-", string.Empty);
string str = "";
return str = "^XA^FO100,100^GFA," + //At Postion 100, 100
bitmapDataSize.ToString() + "," + // Total bytes of data to be placed
bitmapDataSize.ToString() + "," + // Total bytes of data to be placed, repeats as per API
widthInBytes + "," + //
ZPLImageDataString + "^XZ";
使用上面的示例代码,我无法在Zibra标签打印机上打印位图图像。 我不想使用Zebra网桥将bmp转换为GRF图像类型。
任何人都可以告诉我我犯错误的地方吗? 我得到偏移值的方式是错误的吗? (当前它的62,不知道我的图像是否正确。任何人都可以建议我找到位图图像偏移值的公式)
答案 0 :(得分:0)
您可以下载具有库功能的Zebra SDK here来执行此转换和打印。它需要通过几个阶段,抖动以获得每像素1位的黑白需要首先发生,然后调整大小/缩放,然后最终为它创建ZPL。 SDK为你做了所有这些......