如何在C#

时间:2018-03-01 18:36:59

标签: arrays multidimensional-array

我有一个位图像素数据的二维字节数组,我需要通过comport使用ESC / POS发送到热敏打印机。我能成功地做到这一点。但是,我需要将打印的图像向右移动。由于用于打印位图的命令(DC2 * r n [d1 ..... dn]),中心对齐,右对齐,HT和所有其他ESC / POS命令无效。 我希望保留填充包含位图的字节数组,以便将打印图像向右移动。下面是我打印位图的代码行

    private void Print_Bipmap()
    {
        int x;
        int y;
        int i;
        int RowBytes;
        byte n;
        Color Pixels;
        byte[,] ImageArray = new byte[bitmap.Width, bitmap.Height];

        // Calculate output size
        RowBytes = (bitmap.Width + 7) / 8;

        // Generate body of array
        for (y = 0; y < bitmap.Height; y++)
        { // Each row...
            for (x = 0; x < (bitmap.Width / 8); x++)
            { // Each 8-pixel block within row...
                ImageArray[x, y] = 0;
                for (n = 0; n < 8; n++)
                { // Each pixel within block...
                    Pixels = bitmap.GetPixel(x * 8 + n, y);
                    if (Pixels.GetBrightness() < 0.5)
                    {
                        ImageArray[x, y] += (byte)(1 << (7 - n));
                    }
                }
            }
        }

        comport_writeByte(18); //DC2
        comport_writeByte(42); //*
        comport_writeByte((byte)bitmap.Height); //r
        comport_writeByte((byte)RowBytes); //n

        for (y = 0; y < bitmap.Height; y++)
        {
            for (x = 0; x < RowBytes; x++)
            {
              comport_writeByte(ImageArray[x, y]); //[d1 ..... dn]
            }
        }
    }

如何将填充二维数组(ImageArray [x,y])? 非常感谢提前。

0 个答案:

没有答案
相关问题