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); }
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); }
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); }
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); }
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); }
// Builds the front and back side bitmaps // -------------------------------------------------------------------------------------------------- private bool BuildBitmaps() { ZMotifGraphics g = new ZMotifGraphics(); bool builtOk = true; try { // Gets images from files if (_isZXP7) { FrontImage = "ZXP7Front.bmp"; } else { FrontImage = "ZXP8Front.bmp"; } byte[] imgFront = g.ImageFileToByteArray(_nameFrontImage); byte[] imgBack = g.ImageFileToByteArray(_nameBackImage); // Initializes the graphic buffer for the front side g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape, ZMotifGraphics.RibbonTypeEnum.Color); // Draws text and image into the graphic buffer for front side g.DrawImage(ref imgFront, ZMotifGraphics.ImagePositionEnum.Centered, 1000, 620, 0); g.DrawTextString(50, 580, "Front Side: Color Image", "Arial", 10, ZMotifGraphics.FontTypeEnum.Regular, g.IntegerFromColorName("Navy")); // Creates the front side bitmap int dataLen; _bmpFront = g.CreateBitmap(out dataLen); // Clears the graphics buffer g.ClearGraphics(); // Initializes the graphic buffer for the back side g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape, ZMotifGraphics.RibbonTypeEnum.MonoK); // Draws text an image into the graphic buffer for the back side g.DrawImage(ref imgBack, ZMotifGraphics.ImagePositionEnum.Centered, 1000, 620, 0); g.DrawTextString(50, 580, "Back Side Monochrome Image", "Arial", 10, ZMotifGraphics.FontTypeEnum.Regular, g.IntegerFromColorName("Black")); // Creates the back side bitmap _bmpBack = g.CreateBitmap(out dataLen); g.ClearGraphics(); } catch { builtOk = false; } return(builtOk); }
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); } }
private bool Print_Label(string printerName, string frontImagePath, string backImagePath, ref string status) { bool bRet = true; byte[] img = null; byte[] bmpFront = null; byte[] bmpBack = null; Job job = null; ZMotifGraphics g = null; try { // Opens a connection with a ZXP Printer // if it is in an alarm condition, exit function // ------------------------------------------------- job = new Job(); g = new ZMotifGraphics(); if (!Connect(printerName, ref job)) { Debug.WriteLine("Unable to open device [" + printerName + "]\r\n"); return(false); } if (_alarm != 0) { Debug.WriteLine("Printer is in alarm condition\r\n" + "Error: " + job.Device.GetStatusMessageString(_alarm)); return(false); } #region 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, 0, 0, 0); //g.DrawLine(160, 70, 250, 70, g.IntegerFromColor(System.Drawing.Color.Red), 5.0f); //g.DrawRectangle(300, 20, 100, 100, 5.0f, g.IntegerFromColorName("Green")); //g.DrawEllipse(450, 20, 100, 100, 5.0f, g.IntegerFromColor(System.Drawing.Color.Blue)); //g.DrawTextString(50.0f, 580.0f, "Print 1: Front Side: Image, Shapes, Text", "Arial", 10.0f, // ZMotifGraphics.FontTypeEnum.Regular, g.IntegerFromColor(System.Drawing.Color.Navy)); int dataLen; bmpFront = g.CreateBitmap(out dataLen); g.ClearGraphics(); #endregion #region Builds the front side image (color) g.InitGraphics(0, 0, ZMotifGraphics.ImageOrientationEnum.Landscape, ZMotifGraphics.RibbonTypeEnum.MonoK); img = g.ImageFileToByteArray(backImagePath); g.DrawImage(ref img, ZMotifGraphics.ImagePositionEnum.Centered, 0, 0, 0); //g.DrawImage(ref img, 50.0f, 50.0f, 275, 200, 0); //g.DrawLine(350, 50, 475, 120, g.IntegerFromColor(System.Drawing.Color.Black), 5.0f); //g.DrawRectangle(500, 20, 100, 100, 5.0f, g.IntegerFromColorName("Black")); //g.DrawEllipse(650, 20, 100, 100, 5.0f, g.IntegerFromColor(System.Drawing.Color.Black)); //g.DrawTextString(50.0f, 580.0f, "Print 1: Back Side: Image, Shapes, Text", "Arial", 10.0f, // ZMotifGraphics.FontTypeEnum.Regular, g.IntegerFromColor(System.Drawing.Color.DarkBlue)); bmpBack = g.CreateBitmap(out dataLen); g.ClearGraphics(); #endregion #region Print the images //if (!_isZXP7) // job.JobControl.CardType = cardType; job.JobControl.FeederSource = FeederSourceEnum.CardFeeder; job.JobControl.Destination = DestinationTypeEnum.Eject; 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); //string cardUID = SmartCardPrinterUtils.Instance.GetMifareCardUID(EnumDeviceNames.SmartCardPrinterContactlessReader); int actionID = 0; job.PrintGraphicsLayers(1, out actionID); job.ClearGraphicsLayers(); JobWait(ref job, actionID, 180, out status, out bRet); #endregion //return true; } catch (Exception ex) { //return false; } return(bRet); }