Ver Mensaje Individual
  #1  
Antiguo 28-07-2018
RZM107 RZM107 is offline
Registrado
NULL
 
Registrado: jul 2018
Posts: 2
Reputación: 0
RZM107 Va por buen camino
Unhappy Impresion de imagenes ESC POS

Hola soy Raul tengo un problema a la hora de imprimir una imagen por comando escpos, y es q esta me sale con lineas blancas que la cortan y también me sale pixeleada de mas.

Este es el codigo con el que convierto el bitmap en byte[]:

Código:
public byte[] AgregarImagen(String path)
        {
            List<byte> byteList = new List<byte>();
            BitmapData data = GetBitmapData(path);
            BitArray dots = data.Dots;
            byte[] width = BitConverter.GetBytes(data.Width);
            int offset = 0;
            byteList.Add(Convert.ToByte(Convert.ToChar(0x1B)));
            byteList.Add(Convert.ToByte('@'));
            byteList.Add(Convert.ToByte(Convert.ToChar(0x1B)));
            byteList.Add(Convert.ToByte('3'));
            byteList.Add((byte)24);
            while (offset < data.Height)
            {
                byteList.Add(Convert.ToByte(0x1B));
                byteList.Add(Convert.ToByte('*'));
                byteList.Add(Convert.ToByte((byte)33));
                byteList.Add(Convert.ToByte(width[0]));
                byteList.Add(Convert.ToByte(width[1]));
                for (int x = 0; x < data.Width; x++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        byte slice = 0;
                        for (int b = 0; b < 8; b++)
                        {
                            int y = (((offset / 8) + k) * 8) + b;

                            int i = (y * data.Width) + x;

                            bool v = false;
                            if (i < dots.Length)
                            {
                                v = dots[i];
                            }
                            slice |= (byte)((v ? 1 : 0) << (7 - b));
                        }
                        byteList.Add(slice);
                    }
                }
                offset += 24;
                byteList.Add(Convert.ToByte(0x0A));
            }
            byteList.Add(Convert.ToByte(0x1B));
            byteList.Add(Convert.ToByte('3'));
            byteList.Add((byte)30);
            return byteList.ToArray();
        }

        public BitmapData GetBitmapData(String path)
        {
            using (var bitmap = (Bitmap)Bitmap.FromFile(path))
            {
                var th = 127;
                var i = 0;
                double mtp = 570;
                double scl = (double)(mtp / (double)bitmap.Width);
                int yheigth = (int)(bitmap.Height * scl);
                int xwidth = (int)(bitmap.Width * scl);
                var dimensions = xwidth * yheigth;
                var dots = new BitArray(dimensions);
                for (int y = 0; y < yheigth; y++)
                {
                    for (int x = 0; x < xwidth; x++)
                    {
                        var _x = (int)(x / scl);
                        var _y = (int)(y / scl);
                        var color = bitmap.GetPixel(_x, _y);
                        var luminance = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
                        dots[i] = (luminance < th);
                        i++;
                    }
                }
                return new BitmapData()
                {
                    Dots = dots,
                    Height = (int)(bitmap.Height * scl),
                    Width = (int)(bitmap.Width * scl)
                };
            }
        }
       

    }

}
public class BitmapData
{
    public BitArray Dots { get; set; }
    public int Height { get; set; }
    public int Width { get; set; }
}
No se si les sea familiar pero me gustaria que me ayudaran en ellos. La impresora es EPSON TM-TII20 para tiquetes.

Última edición por Neftali [Germán.Estévez] fecha: 30-07-2018 a las 10:16:29. Razón: Añadir etiqueta de CODE
Responder Con Cita