示例#1
0
        private byte[] BuildImageXY(byte[] image, float x, float y, int width, int height, ZMotifGraphics.ImageOrientationEnum ImageOrientation,
                                    ZMotifGraphics.RibbonTypeEnum RibbonType, out string errMsg)
        {
            errMsg = string.Empty;

            byte[] TheImage = null;

            ZMotifGraphics graphics = null;

            try
            {
                int dataLen = 0;

                graphics = new ZMotifGraphics();

                graphics.InitGraphics(0, 0, ImageOrientation, RibbonType);

                if (RibbonType != ZMotifGraphics.RibbonTypeEnum.Color)
                {
                    graphics.ColorProfile = string.Empty;
                }

                graphics.DrawImage(ref image, x, y, width, height, (float)0.0);


                if (image != null)
                {
                    TheImage = graphics.CreateBitmap(out dataLen);
                }

                return(TheImage);
            }
            catch (Exception ex)
            {
                TheImage = null;
                errMsg   = ex.StackTrace;
            }
            finally
            {
                graphics.ClearGraphics();
                graphics.CloseGraphics();
                graphics = null;
            }
            return(null);
        }
示例#2
0
        private byte[] BuildOverlayImage(byte[] image, out string errMsg)
        {
            errMsg = string.Empty;

            byte[] TheImage = null;

            ZMotifGraphics graphics = null;

            try
            {
                int dataLen = 0;

                graphics = new ZMotifGraphics();

                ZMotifGraphics.RibbonTypeEnum       RibbonType       = ZMotifGraphics.RibbonTypeEnum.Overlay;
                ZMotifGraphics.ImageOrientationEnum ImageOrientation = ZMotifGraphics.ImageOrientationEnum.Landscape;

                graphics.InitGraphics(0, 0, ImageOrientation, RibbonType);

                graphics.ColorProfile = string.Empty;

                graphics.DrawImage(ref image, ZMotifGraphics.ImagePositionEnum.Centered, 1100, 700, 0);

                if (image != null)
                {
                    TheImage = graphics.CreateBitmap(out dataLen);
                }

                return(TheImage);
            }
            catch (Exception ex)
            {
                TheImage = null;
                errMsg   = ex.StackTrace;
            }
            finally
            {
                graphics.ClearGraphics();
                graphics.CloseGraphics();
                graphics = null;
            }
            return(null);
        }
示例#3
0
        private byte[] BuildText(string text, float x, float y, string font, float fontSize, int fontColour, ZMotifGraphics.FontTypeEnum fontType,
                                 ZMotifGraphics.ImageOrientationEnum ImageOrientation, ZMotifGraphics.RibbonTypeEnum RibbonType, out string errMsg)
        {
            errMsg = string.Empty;

            byte[] TheImage = null;

            ZMotifGraphics graphics = null;

            try
            {
                int dataLen = 0;

                graphics = new ZMotifGraphics();

                graphics.InitGraphics(0, 0, ImageOrientation, RibbonType);

                if (RibbonType != ZMotifGraphics.RibbonTypeEnum.Color)
                {
                    graphics.ColorProfile = string.Empty;
                }

                graphics.DrawTextString(x, y, text, font, fontSize, fontType, fontColour);

                TheImage = graphics.CreateBitmap(out dataLen);

                return(TheImage);
            }
            catch (Exception ex)
            {
                TheImage = null;
                errMsg   = ex.StackTrace;
            }
            finally
            {
                graphics.ClearGraphics();
                graphics.CloseGraphics();
                graphics = null;
            }
            return(null);
        }
示例#4
0
        private byte[] BuildTest(ZMotifGraphics.ImageOrientationEnum ImageOrientation, ZMotifGraphics.RibbonTypeEnum RibbonType, out string errMsg)
        {
            errMsg = string.Empty;

            byte[] TheImage = null;

            ZMotifGraphics graphics = null;

            try
            {
                int dataLen = 0;

                graphics = new ZMotifGraphics();

                graphics.InitGraphics(0, 0, ImageOrientation, RibbonType);

                if (RibbonType != ZMotifGraphics.RibbonTypeEnum.Color)
                {
                    graphics.ColorProfile = string.Empty;
                }

                graphics.DrawRectangle(20, 20, DEFAULT_WIDTH - 40, DEFAULT_HEIGHT - 40, 10, System.Drawing.Color.Black.ToArgb());
                graphics.DrawTextString(25, 25, "PRINT TEST", "Arial", 12, ZMotifGraphics.FontTypeEnum.Bold, System.Drawing.Color.Black.ToArgb());

                TheImage = graphics.CreateBitmap(out dataLen);

                return(TheImage);
            }
            catch (Exception ex)
            {
                TheImage = null;
                errMsg   = ex.StackTrace;
            }
            finally
            {
                graphics.ClearGraphics();
                graphics.CloseGraphics();
                graphics = null;
            }
            return(null);
        }
        public bool Perform_Set_Error_Recovery_Mode_Print(string cardType)
        {
            bool bRet = true;

            byte[] img     = null;
            byte[] bmp     = null;
            byte[] monoBmp = null;

            Job            job = null;
            ZMotifGraphics g   = null;

            try
            {
                job = new Job();
                g   = new ZMotifGraphics();

                // Opens a connection with a ZXP Printer
                //     if it is in an alarm condition, exit function
                // -------------------------------------------------

                if (!Connect(ref job))
                {
                    _msg = "Unable to open device [" + _deviceName + "]";
                    return(false);
                }

                if (_alarm != 0)
                {
                    _msg = "Printer is in alarm condition" + "Error: " + job.Device.GetStatusMessageString(_alarm);
                    return(false);
                }

                if (_isZXP7)
                {
                    FrontImage = "ZXP7Front.bmp";
                }
                else
                {
                    FrontImage = "ZXP8Front.bmp";
                }

                img = g.ImageFileToByteArray(FrontImage);

                // Builds the image to print
                // -------------------------

                g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape,
                               ZMotifGraphics.RibbonTypeEnum.Color);

                g.DrawImage(ref img, 50, 50, 924, 548, 0);
                g.DrawTextString(50.0f, 580.0f, "Color + Set Error Recovery Mode", "Arial", 10.0f,
                                 ZMotifGraphics.FontTypeEnum.Regular,
                                 g.IntegerFromColor(System.Drawing.Color.Black));

                int dataLen = 0;
                bmp = g.CreateBitmap(out dataLen);

                g.ClearGraphics();

                //re-init graphics for MonoK panel
                g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape,
                               ZMotifGraphics.RibbonTypeEnum.MonoK);

                //load image to be printed as MonoK panel:
                img = g.ImageFileToByteArray("Back.bmp");
                g.DrawImage(ref img, 50, 50, 924, 548, 0);

                dataLen = 0;
                monoBmp = g.CreateBitmap(out dataLen);

                // Print image on both sides
                // -------------------------

                if (!_isZXP7)
                {
                    job.JobControl.CardType = cardType;
                }

                job.JobControl.FeederSource = FeederSourceEnum.CardFeeder;

                if (job.Device.HasLaminator)
                {
                    job.JobControl.Destination = DestinationTypeEnum.LaminatorAny;
                }
                else
                {
                    job.JobControl.Destination = DestinationTypeEnum.Eject;
                }

                //SET ERROR RECOVERY MODE FOR PRINTER:
                job.Device.ErrorControlLevel = ErrorControlLevelEnum.EC_None;

                job.BuildGraphicsLayers(SideEnum.Front, PrintTypeEnum.Color, 0, 0, 0, -1, GraphicTypeEnum.BMP, bmp);

                job.BuildGraphicsLayers(SideEnum.Back, PrintTypeEnum.MonoK, 0, 0, 0, -1, GraphicTypeEnum.BMP, monoBmp);

                int actionID = 0;
                job.PrintGraphicsLayers(1, out actionID);

                job.ClearGraphicsLayers();

                string status = string.Empty;
                JobWait(ref job, actionID, 180, out status);
            }
            catch (Exception e)
            {
                bRet = false;
                _msg = e.Message;
            }
            finally
            {
                g.CloseGraphics();
                g = null;

                img = null;
                bmp = null;

                Disconnect(ref job);
            }
            return(bRet);
        }
示例#6
0
        public bool Perform_MonochromePrint(string cardType)
        {
            bool bRet = true;

            byte[] img      = null;
            byte[] bmp      = null;
            byte[] colorBmp = null;
            byte[] monoBmp  = null;

            Job            job = null;
            ZMotifGraphics g   = null;

            try
            {
                job = new Job();
                g   = new ZMotifGraphics();

                // Opens a connection with a ZXP Printer
                //     if it is in an alarm condition, exit function
                // -------------------------------------------------

                if (!Connect(ref job))
                {
                    _msg = "Unable to open device [" + _deviceName + "]";
                    return(false);
                }

                if (_alarm != 0)
                {
                    _msg = "Printer is in alarm condition" + "Error: " + job.Device.GetStatusMessageString(_alarm);
                    return(false);
                }

                if (_isZXP7)
                {
                    FrontImage = "ZXP7Front.bmp";
                }
                else
                {
                    FrontImage = "ZXP8Front.bmp";
                }


                img = g.ImageFileToByteArray(FrontImage);

                // Builds the image to print
                // -------------------------

                g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape,
                               ZMotifGraphics.RibbonTypeEnum.Color);

                g.DrawImage(ref img, 50, 50, 924, 548, 0);
                g.DrawTextString(50.0f, 580.0f, "Monochrome Print", "Arial", 10.0f,
                                 ZMotifGraphics.FontTypeEnum.Regular,
                                 g.IntegerFromColor(System.Drawing.Color.Black));

                int dataLen;
                bmp = g.CreateBitmap(out dataLen);
                g.ExtractBlackData(ref bmp, ref colorBmp, ref monoBmp);

                g.ClearGraphics();

                if (!_isZXP7)
                {
                    job.JobControl.CardType = cardType;
                }

                job.JobControl.FeederSource = FeederSourceEnum.CardFeeder;

                if (job.Device.HasLaminator)
                {
                    job.JobControl.Destination = DestinationTypeEnum.LaminatorAny;
                }
                else
                {
                    job.JobControl.Destination = DestinationTypeEnum.Eject;
                }

                //job.BuildGraphicsLayers(SideEnum.Front, PrintTypeEnum.Color, 0, 0, 0,
                //                        -1, GraphicTypeEnum.BMP, colorBmp);

                job.BuildGraphicsLayers(SideEnum.Front, PrintTypeEnum.MonoK, 0, 0, 0,
                                        -1, GraphicTypeEnum.BMP, monoBmp);

                int actionID = 0;
                job.PrintGraphicsLayers(1, out actionID);

                job.ClearGraphicsLayers();

                string status = string.Empty;
                JobWait(ref job, actionID, 180, out status);
            }
            catch (Exception e)
            {
                bRet = false;
                _msg = e.Message;
            }
            finally
            {
                g.CloseGraphics();
                g = null;

                img = null;
                bmp = null;

                Disconnect(ref job);
            }
            return(bRet);
        }
示例#7
0
        public bool PrintAndWriteSmartCard(PrintAndWriteSmartCardInfo cardInfo, Action <PrintAndWriteCardResult> OnCompleted)
        {
            try
            {
                // validate
                if (cardInfo == null)
                {
                    throw new Exception("cardInfo can not be null");
                }
                PrintAndWriteCardResult returnValue = new PrintAndWriteCardResult()
                {
                    Success = false
                };

                if (IsPrinterConnected(EnumDeviceNames.SmartCardPrinterName))
                {
                    #region use SmartCardPrinterName
                    byte[] img      = null;
                    byte[] bmpFront = null;
                    byte[] bmpBack  = null;

                    Job            job = null;
                    ZMotifGraphics g   = null;

                    string frontImagePath, backImagePath = null;

                    try
                    {
                        job = new Job();
                        g   = new ZMotifGraphics();

                        // Opens a connection with a ZXP Printer
                        //     if it is in an alarm condition, exit function
                        // -------------------------------------------------

                        if (!Connect(ref job))
                        {
                            throw new Exception("Unable to open device [" + _smartCardPrinterName + "]\r\n");
                        }

                        // Determines if the ZXP device supports smart card encoding
                        // ---------------------------------------------------------
                        if (!GetPrinterConfiguration(ref job, out bool isContactless))
                        {
                            throw new Exception("Unable to get printer configuration");
                        }

                        if (!isContactless)
                        {
                            throw new Exception("Printer is not configured for Contactless Encoding");
                        }

                        if (_alarm != 0)
                        {
                            throw new Exception("Printer is in alarm condition\r\n");
                        }

                        frontImagePath = cardInfo.FrontCardImagePath;
                        backImagePath  = cardInfo.BackCardImagePath;

                        // Builds the front side image (color)
                        // -----------------------------------

                        g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape,
                                       ZMotifGraphics.RibbonTypeEnum.Color);

                        img = g.ImageFileToByteArray(frontImagePath);
                        g.DrawImage(ref img, ZMotifGraphics.ImagePositionEnum.Centered, 1024, 648, 0);

                        int dataLen = 0;
                        bmpFront = g.CreateBitmap(out dataLen);
                        g.ClearGraphics();

                        // Builds the back side image (monochrome)
                        // ---------------------------------------

                        g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape,
                                       ZMotifGraphics.RibbonTypeEnum.MonoK);

                        img = g.ImageFileToByteArray(backImagePath);
                        g.DrawImage(ref img, ZMotifGraphics.ImagePositionEnum.Centered, 1024, 648, 0);

                        bmpBack = g.CreateBitmap(out dataLen);
                        g.ClearGraphics();

                        // Start a contactless smart card job
                        // -----------------------

                        //job.JobControl.CardType = GetContactlessCardType(ref job);
                        //job.JobControl.CardType = "PVC,MIFARE,4K";

                        job.JobControl.FeederSource = FeederSourceEnum.CardFeeder;
                        job.JobControl.Destination  = DestinationTypeEnum.Eject;

                        job.JobControl.SmartCardConfiguration(SideEnum.Front, SmartCardTypeEnum.MIFARE, true);

                        job.BuildGraphicsLayers(SideEnum.Front, PrintTypeEnum.Color, 0, 0, 0,
                                                -1, GraphicTypeEnum.BMP, bmpFront);

                        job.BuildGraphicsLayers(SideEnum.Back, PrintTypeEnum.MonoK, 0, 0, 0,
                                                -1, GraphicTypeEnum.BMP, bmpBack);

                        int actionID = 0;
                        job.PrintGraphicsLayers(1, out actionID);

                        job.ClearGraphicsLayers();

                        // Waits for the card to reach the smart card station
                        // --------------------------------------------------
                        string status = string.Empty;
                        AtStation(ref job, actionID, 30, out status);

                        // ***** Smart Card Code goes here *****
                        SmartCardData_Original cardData = new SmartCardData_Original()
                        {
                            SuperviseeBiodata = cardInfo.SuperviseeBiodata,
                            DutyOfficerData   = cardInfo.DutyOfficerData
                        };
                        // write data
                        bool writeDataResult = SmartCardReaderUtil.Instance.WriteData(cardData, EnumDeviceNames.SmartCardPrinterContactlessReader);
                        if (writeDataResult)
                        {
                            // get card UID
                            returnValue.CardUID = SmartCardReaderUtil.Instance.GetCardUID(EnumDeviceNames.SmartCardPrinterContactlessReader);
                        }

                        // At the completion of smart card process
                        //     if the smart card encoding was successful JobResume
                        //     if the smart card encoding was Unsuccessful JobAbort
                        // --------------------------------------------------------

                        if (writeDataResult)
                        {
                            JobResume(ref job);
                        }
                        else
                        {
                            JobAbort(ref job, true);
                        }

                        JobWait(ref job, actionID, 180, out status);

                        // need to verify printing status
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message);
                    }
                    finally
                    {
                        g.CloseGraphics();
                        g = null;

                        img      = null;
                        bmpFront = null;
                        bmpBack  = null;

                        Disconnect(ref job);
                    }
                    #endregion
                }
                else if (SmartCardReaderUtil.Instance.GetDeviceStatus().Contains(EnumDeviceStatus.Connected))
                {
                    #region use card reader
                    SmartCardData_Original cardData = new SmartCardData_Original()
                    {
                        SuperviseeBiodata = cardInfo.SuperviseeBiodata,
                        DutyOfficerData   = cardInfo.DutyOfficerData
                    };
                    // write data
                    bool writeDataResult = SmartCardReaderUtil.Instance.WriteData(cardData);
                    if (writeDataResult)
                    {
                        // get card UID
                        returnValue.CardUID = SmartCardReaderUtil.Instance.GetCardUID(EnumDeviceNames.SmartCardContactlessReader);
                    }
                    #endregion
                }
                else
                {
                    returnValue.Description = "Smart card printer is not connected!";
                }


                if (!string.IsNullOrEmpty(returnValue.CardUID))
                {
                    returnValue.Success = true;
                }
                else if (string.IsNullOrEmpty(returnValue.CardUID) && string.IsNullOrEmpty(returnValue.Description))
                {
                    returnValue.Description = "Smart card type unsupported!";
                }

                OnCompleted(returnValue);
                return(returnValue.Success);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("PrintAndWriteSmartcardData exception: " + ex.ToString());
                OnCompleted(new PrintAndWriteCardResult()
                {
                    Success = false, Description = "Oops!.. Something went wrong ..."
                });
                return(false);
            }
        }