从标题中可以看出,这个问题过去曾讨论过。我已将之前的帖子作为参考,并尝试在 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,不知道我的图像是否正确。谁能建议我找到位图图像偏移值的公式)