【问题标题】:Printing the bitmap image on ZPL label printer在 ZPL 标签打印机上打印位图图像
【发布时间】:2022-05-03 16:04:25
【问题描述】:

从标题中可以看出,这个问题过去曾讨论过。我将之前的帖子作为参考,并尝试在 Zebra 标签打印机上打印位图图像。我无法打印我正在寻找的图像。请不要忽略,因为它已经讨论过。

请查看下面提到的代码sn-p:

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,不知道我的图像是否正确。谁能建议我找到位图图像偏移值的公式)

【问题讨论】:

    标签: zebra-printers


    【解决方案1】:

    你可以下载Zebra SDK here,它有一个库函数来做这个转换和打印。它需要经历几个阶段,首先需要进行抖动以达到每像素 1 位的黑白,然后调整大小/缩放,最后为它创建 ZPL。 SDK 为您完成所有这些工作...

    【讨论】:

    • 我尝试使用 Zebra SDK,但在导入非托管 dll 时遇到问题(无法提取这些 dll 的方法,第三方工具限制)。有没有其他方法可以修改代码,以便我可以解决在 RZ400 标签打印机上打印位图图像的问题。如何对给定图像进行缩放?请帮助我。
    • 我可以在 Multiplatform SDK 的帮助下进行打印,但这并不能解决我的问题,因为我必须准备 ZPL 命令。正如您所说,我的 C# 解决方案需要一些扩展,请您帮我解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多