Example #1
0
        private List <GraphicsInfo> CreateGraphicsInfo(ZebraGraphics graphics, Dictionary <PrintType, string> imageInfo, CardSide side)
        {
            List <GraphicsInfo> graphicsInfoList = new List <GraphicsInfo>();

            foreach (PrintType type in imageInfo.Keys)
            {
                graphics.Initialize(0, 0, OrientationType.Landscape, type, -1);

                if (type == PrintType.Overlay && imageInfo[type] == null)
                {
                    GraphicsInfo graphicsInfo = new GraphicsInfo {
                        Side        = side,
                        PrintType   = type,
                        GraphicType = GraphicType.NA
                    };
                    graphicsInfoList.Add(graphicsInfo);
                }
                else
                {
                    byte[] imageData = File.ReadAllBytes(imageInfo[type]);
                    graphics.DrawImage(imageData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                    graphicsInfoList.Add(BuildGraphicsInfo(graphics.CreateImage(), side, type));
                }

                graphics.Clear();
            }

            return(graphicsInfoList);
        }
Example #2
0
        private byte[] CropImage(ZebraGraphics graphics, byte[] imageData, int croppedWidth, int croppedHeight)
        {
            int xOffset = viewModel.XOffset < 0 ? 0 : viewModel.XOffset;
            int yOffset = viewModel.YOffset < 0 ? 0 : viewModel.YOffset;

            JobStatusControl.UpdateLog($"Cropping image from xOffset:{xOffset} yOffset:{yOffset} with width:{croppedWidth} and height:{croppedHeight}...");
            byte[] croppedImage = graphics.CropImage(imageData, xOffset, yOffset, croppedWidth, croppedHeight);

            JobStatusControl.UpdateLog("Finished cropping image");
            return(croppedImage);
        }
Example #3
0
        private void ApplyMonochromeConversion(ZebraGraphics graphics, PrintType printType, MonochromeConversion monochromeConversionType)
        {
            JobStatusControl.UpdateLog("Converting graphic...");

            if (printType != PrintType.MonoK && printType != PrintType.GrayDye)
            {
                switch (monochromeConversionType)
                {
                case MonochromeConversion.Diffusion:
                    JobStatusControl.UpdateLog("Ignoring diffusion option for non-mono/gray format type...");
                    break;

                case MonochromeConversion.HalfTone_6x6:
                case MonochromeConversion.HalfTone_8x8:
                    JobStatusControl.UpdateLog("Ignoring halftone option for non-mono/gray format type...");
                    break;
                }
            }
            else
            {
                switch (monochromeConversionType)
                {
                case MonochromeConversion.Diffusion:
                    graphics.MonochromeConverionType = MonochromeConversion.Diffusion;
                    JobStatusControl.UpdateLog("Applying diffusion algorithm...");
                    break;

                case MonochromeConversion.HalfTone_6x6:
                    graphics.MonochromeConverionType = MonochromeConversion.HalfTone_6x6;
                    JobStatusControl.UpdateLog("Applying 6x6 halftone algorithm...");
                    break;

                case MonochromeConversion.HalfTone_8x8:
                    graphics.MonochromeConverionType = MonochromeConversion.HalfTone_8x8;
                    JobStatusControl.UpdateLog("Applying 8x8 halftone algorithm...");
                    break;
                }
            }
        }
        // <exception cref="ConnectionException"></exception>
        // <exception cref="IOException"></exception>
        // <exception cref="NotSupportedException"></exception>
        // <exception cref="System.Security.SecurityException"></exception>
        // <exception cref="UnauthorizedAccessException"></exception>
        // <exception cref="Zebra.Sdk.Card.Exceptions.ZebraCardException"></exception>
        // <exception cref="Zebra.Sdk.Device.ZebraIllegalArgumentException"></exception>

        private ZebraCardImageI DrawCarnetBack(ZebraGraphics graphics, PrintType printType, DataTable data)
        {
            int positionx = 775;
            int positiony = 380;

            Font   font             = new Font("Arial", 7, FontStyle.Bold);
            Font   fontIGSS         = new Font("Arial", 9, FontStyle.Bold);
            Font   fontFechaEmision = new Font("Arial", 5, FontStyle.Regular);
            string Recomendaciones  = "La  empresa no se hace responsable por el mal uso de este carné, " +
                                      "el cual es válido únicamente dentro de nuestras instalaciones y durante el periodo de relación laboral." +
                                      " En caso  de emergencia  comunicarse con Recursos Humanos   al 7820-1700.";
            string NumeroDeEmpleado = data.Rows[0]["NumeroDeEmpleado"].ToString();
            string ImpresionCarnet  = data.Rows[0]["ImpresionCarnet"].ToString();
            string AfiliacionIGSS   = data.Rows[0]["AfiliacionIGSS"].ToString();

            graphics.Initialize(0, 0, OrientationType.Landscape, printType, Color.White);

            graphics.DrawText(Recomendaciones, font, Color.Black, 10, 10, 1000, 200, 0, TextAlignment.Left, TextAlignment.Center);


            using (Code39Util code39 = ZebraBarcodeFactory.GetCode39(graphics))
            {
                code39.ValueToEncode  = NumeroDeEmpleado + "-" + ImpresionCarnet;
                code39.QuietZoneWidth = 0;
                code39.DrawBarcode(100, 190, 800, 180);
            }

            if (File.Exists(@"\\nastrfca1\ArchivosAdjuntosSistemas\Carnet\" + NumeroDeEmpleado + "VCARDV3.png"))
            {
                string QRVCardImagePath = @"\\nastrfca1\ArchivosAdjuntosSistemas\Carnet\" + NumeroDeEmpleado + "VCARDV3.png";
                byte[] QRVCardimageData = File.ReadAllBytes(QRVCardImagePath);
                graphics.DrawImage(QRVCardimageData, 10, 380, 270, 270, RotationType.RotateNoneFlipNone);
            }
            else
            {
                positionx = 10;
                positiony = 380;
            }


            graphics.DrawText("Afiliación IGSS: ", font, Color.Black, 280, 405, 600, 45, 0, TextAlignment.Left, TextAlignment.Center);
            if (!string.IsNullOrEmpty(AfiliacionIGSS))
            {
                graphics.DrawText(AfiliacionIGSS, fontIGSS, Color.Black, 280, 435, 600, 50, 0, TextAlignment.Left, TextAlignment.Center);
            }

            graphics.DrawText("Teléfono Clínica Médica:", font, Color.Black, 280, 480, 600, 45, 0, TextAlignment.Left, TextAlignment.Center);
            graphics.DrawText("7820 1746", fontIGSS, Color.Black, 280, 510, 600, 45, 0, TextAlignment.Left, TextAlignment.Center);
            graphics.DrawText("Fecha de Emisión:", fontFechaEmision, Color.Black, 280, 540, 600, 45, 0, TextAlignment.Left, TextAlignment.Center);
            graphics.DrawText(DateTime.Now.ToString("dd/MM/yyyy"), fontFechaEmision, Color.Black, 280, 570, 600, 45, 0, TextAlignment.Left, TextAlignment.Center);



            using (QRCodeUtil qrCode = ZebraBarcodeFactory.GetQRCode(graphics))
            {
                qrCode.ValueToEncode = NumeroDeEmpleado;
                qrCode.DrawBarcode(positionx, positiony, 180, 180);
            }

            return(graphics.CreateImage());
        }
 /// <exception cref="Zebra.Sdk.Card.Exceptions.ZebraCardException"></exception>
 /// <exception cref="Zebra.Sdk.Device.ZebraIllegalArgumentException"></exception>
 private static ZebraCardImageI DrawImage(ZebraGraphics graphics, PrintType printType, byte[] imageData, int xOffset, int yOffset, int width, int height)
 {
     graphics.Initialize(0, 0, OrientationType.Landscape, printType, Color.White);
     graphics.DrawImage(imageData, xOffset, yOffset, width, height, RotationType.RotateNoneFlipNone);
     return(graphics.CreateImage());
 }
        private ZebraCardImageI DrawCarnetFront(ZebraGraphics graphics, PrintType printType, DataTable data)
        {
            Font font      = new Font("Arial", 9, FontStyle.Bold);
            Font fontlabel = new Font("Arial", 6, FontStyle.Bold);
            Font fontlabelNumeroEmpleado = new Font("Arial", 6, FontStyle.Bold);

            char[] spacewhite = new char[] { ' ' };
            string NombreDepartamentoEmpresa  = null;
            string NombreDepartamentoEmpresa2 = null;
            string NombrePuestoEmpresa        = null;
            string NombrePuestoEmpresa2       = null;
            int    puestosplit       = 1;
            int    departamentosplit = 1;

            graphics.Initialize(0, 0, OrientationType.Landscape, printType, Color.White);

            string colorImagePath = @"C:\logos\" + data.Rows[0]["Empresa"].ToString() + ".jpg";

            byte[] imageData = File.ReadAllBytes(colorImagePath);
            string RutaFoto  = data.Rows[0]["RutaFoto"].ToString().Replace("http://*****:*****@"\\nastrfca1\ArchivosAdjuntosSistemas\Carnet\");

            byte[] imagePhoto = File.ReadAllBytes(RutaFoto);

            string Nombre           = data.Rows[0]["Nombres"].ToString();
            string Apellidos        = data.Rows[0]["Apellidos"].ToString();
            string Departamento     = data.Rows[0]["NombreDepartamento"].ToString();
            string Puesto           = data.Rows[0]["NombrePuesto"].ToString();
            string NumeroDeEmpleado = data.Rows[0]["NumeroDeEmpleado"].ToString();
            string DPI = data.Rows[0]["DPI"].ToString();


            graphics.DrawImage(imageData, 10, 10, 450, 150, RotationType.RotateNoneFlipNone);
            graphics.DrawImage(imagePhoto, 560, 0, 445, 460, RotationType.RotateNoneFlipNone);

            graphics.DrawText("Puesto:", fontlabel, Color.FromArgb(2, 115, 199), xposition, 160, 0);

            if (Puesto.Length >= 35)
            {
                if (Puesto.Split(spacewhite).Length >= 2)
                {
                    puestosplit = 2;
                }
            }

            if (Puesto.Split(spacewhite).Length >= 4)
            {
                puestosplit = 2;
            }

            if (Puesto.Split(spacewhite).Length >= 5)
            {
                puestosplit = 3;
            }

            if (Puesto.Split(spacewhite).Length >= 7)
            {
                puestosplit = 4;
            }

            if (Puesto.Length >= 30)
            {
                for (int i = 0; i < Puesto.Split(spacewhite).Length; i++)
                {
                    if (i < Puesto.Split(spacewhite).Length - puestosplit)
                    {
                        NombrePuestoEmpresa += Puesto.Split(spacewhite)[i].ToString() + " ";
                    }
                    else
                    {
                        NombrePuestoEmpresa2 += Puesto.Split(spacewhite)[i].ToString() + " ";
                    }
                }
                if (!string.IsNullOrEmpty(NombrePuestoEmpresa))
                {
                    graphics.DrawText(NombrePuestoEmpresa, font, Color.Black, xposition, 190, 540, 45, 0, TextAlignment.Left, TextAlignment.Top, true);
                    graphics.DrawText(NombrePuestoEmpresa2, font, Color.Black, xposition, 225, 540, 45, 0, TextAlignment.Left, TextAlignment.Top, true);
                }
                else
                {
                    graphics.DrawText(NombrePuestoEmpresa2, font, Color.Black, xposition, 190, 540, 45, 0, TextAlignment.Left, TextAlignment.Top, true);
                }
            }

            else
            {
                graphics.DrawText(Puesto, font, Color.Black, xposition, 190, 540, 50, 0, TextAlignment.Left, TextAlignment.Top, true);
            }



            graphics.DrawText("Departamento:", fontlabel, Color.FromArgb(2, 115, 199), xposition, 290, 0);

            if (Departamento.Length >= 35)
            {
                if (Departamento.Split(spacewhite).Length >= 2)
                {
                    departamentosplit = 2;
                }
            }

            if (Departamento.Split(spacewhite).Length >= 2)
            {
                departamentosplit = 3;
            }

            if (Departamento.Split(spacewhite).Length >= 5)
            {
                departamentosplit = 4;
            }

            if (Departamento.Split(spacewhite).Length >= 7)
            {
                departamentosplit = 5;
            }

            if (Departamento.Length >= 30)
            {
                for (int i = 0; i < Departamento.Split(spacewhite).Length; i++)
                {
                    if (i < Departamento.Split(spacewhite).Length - departamentosplit)
                    {
                        NombreDepartamentoEmpresa += Departamento.Split(spacewhite)[i].ToString() + " ";
                    }
                    else
                    {
                        NombreDepartamentoEmpresa2 += Departamento.Split(spacewhite)[i].ToString() + " ";
                    }
                }
                if (!string.IsNullOrEmpty(NombreDepartamentoEmpresa))
                {
                    graphics.DrawText(NombreDepartamentoEmpresa, font, Color.Black, xposition, 320, 540, 45, 0, TextAlignment.Left, TextAlignment.Top, true);
                    graphics.DrawText(NombreDepartamentoEmpresa2, font, Color.Black, xposition, 355, 540, 45, 0, TextAlignment.Left, TextAlignment.Bottom, true);
                }
                else

                {
                    graphics.DrawText(NombreDepartamentoEmpresa2, font, Color.Black, xposition, 320, 540, 45, 0, TextAlignment.Left, TextAlignment.Top, true);
                }
            }
            else
            {
                graphics.DrawText(Departamento, font, Color.Black, xposition, 320, 540, 50, 0, TextAlignment.Left, TextAlignment.Top, true);
            }

            //}



            //graphics.DrawText("DPI:", fontlabel, Color.FromArgb(2, 115, 199), 40, 355, 0);
            //graphics.DrawText(DPI, font, Color.Black, 40, 380, 0);



            //graphics.DrawText(Apellidos, font, Color.Black, 40, 220, 0);



            graphics.DrawLine(new PointF(0, 540), new PointF(1100, 540), 150, Color.FromArgb(2, 115, 199));

            graphics.DrawText(Nombre + " " + Apellidos, font, Color.White, 0, 440, 1000, 100, 0, TextAlignment.Center, TextAlignment.Center);
            graphics.DrawText("-DPI-", fontlabelNumeroEmpleado, Color.White, 0, 480, 1000, 100, 0, TextAlignment.Center, TextAlignment.Center);
            graphics.DrawText(DPI, font, Color.White, 0, 515, 1000, 100, 0, TextAlignment.Center, TextAlignment.Center);



            return(graphics.CreateImage());
        }
Example #7
0
        private async void ConvertButton_Click(object sender, RoutedEventArgs e)
        {
            JobStatusControl.ClearLog();

            await Task.Run(() => {
                ZebraGraphics graphics = null;

                try {
                    graphics = new ZebraCardGraphics(null)
                    {
                        PrinterModel = viewModel.SelectedPrinterModelInfo.PrinterModel
                    };

                    if (!Path.IsPathRooted(viewModel.OriginalGraphicFilename))
                    {
                        throw new ArgumentException("Original graphic filename must be an absolute path");
                    }

                    System.Drawing.Image image = ImageHelper.CreateImageFromFile(viewModel.OriginalGraphicFilename);
                    byte[] imageData           = ImageHelper.ConvertImage(image);

                    int width;  // Width of final output image
                    int height; // Height of final output image

                    switch (viewModel.SelectedDimensionOption)
                    {
                    case DimensionOption.Crop:
                        int croppedWidth  = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                        int croppedHeight = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);
                        imageData         = CropImage(graphics, imageData, croppedWidth, croppedHeight);

                        width  = croppedWidth;
                        height = croppedHeight;
                        break;

                    case DimensionOption.Resize:
                        width  = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                        height = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);

                        JobStatusControl.UpdateLog($"Resizing image to {width}x{height}...");
                        break;

                    case DimensionOption.Original:
                    default:
                        width  = ConstrainWidth(image.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                        height = ConstrainHeight(image.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);

                        JobStatusControl.UpdateLog("Keeping current image dimensions unless they exceed the maximum model-specific width and height...");
                        break;
                    }

                    GraphicsFormat graphicsFormat = viewModel.SelectedGraphicsFormat;
                    MonochromeConversion monochromeConversionType = viewModel.SelectedGraphicsFormat.GetMonochromeConversion();
                    PrintType printType             = viewModel.SelectedGraphicsFormat.GetPrintType();
                    OrientationType orientationType = OrientationType.Landscape;

                    JobStatusControl.UpdateLog($"Setting orientation to {orientationType}...");

                    graphics.Initialize(width, height, orientationType, printType, System.Drawing.Color.White);
                    graphics.DrawImage(imageData, 0, 0, width, height, RotationType.RotateNoneFlipNone);
                    ApplyMonochromeConversion(graphics, printType, monochromeConversionType);

                    JobStatusControl.UpdateLog($"Writing graphic file to path {viewModel.ConvertedGraphicFilename}...");

                    WriteToFile(viewModel.ConvertedGraphicFilename, graphics.CreateImage().ImageData);

                    JobStatusControl.UpdateLog("Finished converting graphic");
                } catch (Exception exception) {
                    string errorMessage = $"Error converting graphic: {exception.Message}";
                    JobStatusControl.UpdateLog(errorMessage);
                    MessageBoxHelper.ShowError(errorMessage);
                } finally {
                    if (graphics != null)
                    {
                        graphics.Close();
                    }
                }
            });
        }