Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   .NET (https://www.clubdelphi.com/foros/forumdisplay.php?f=17)
-   -   Impresion de imagenes ESC POS (https://www.clubdelphi.com/foros/showthread.php?t=93308)

RZM107 28-07-2018 00:58:53

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.

mRoman 28-07-2018 01:22:27

Mi estimado Raúl...algunas preguntas para los que consulten tu hilo:

Que base de datos usas?
Q componentes utilizas?

(De seguro te harán referencia acerca de las etiquetas).

Saludos.

RZM107 28-07-2018 02:04:13

Cita:

Empezado por mRoman (Mensaje 527824)
Mi estimado Raúl...algunas preguntas para los que consulten tu hilo:

Que base de datos usas?
Q componentes utilizas?

(De seguro te harán referencia acerca de las etiquetas).

Saludos.

No uso ninguna base de datos por ahora es solo una prueba a realizar.
En cuanto los componentes solo uso botones.


La franja horaria es GMT +2. Ahora son las 16:21:51.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi