public bool DrawPhoto(PrintParameter printPra, ref ZBRGraphics g) { Image img = null; LogHelper.WriteLog(typeof(PrintFormatView), "photo path:" + printPra.personPhoto); if (printPra.personPhoto.Equals("") || !File.Exists(printPra.personPhoto)) { img = Properties.Resources.blank; } else { LogHelper.WriteLog(typeof(PrintFormatView), "printPra.personPhoto:" + printPra.personPhoto); img = MyImage.GetFile(printPra.personPhoto); //img = Image.FromFile(printPra.personPhoto); } if (img == null) { return(false); } int _fwhith = Convert.ToInt32(GetHPixel(20.0f)); int _fHight = Convert.ToInt32(GetVPixel(25.0f)); string[] pos = printPra.photoPos.Split(','); int X = Convert.ToInt32(GetHPixel((float)Convert.ToDouble(pos[0]))); int Y = Convert.ToInt32(GetVPixel((float)Convert.ToDouble(pos[1]))); //int ret = PrintPicture((int)X, (int)Y, printPra.personPhoto, (int)_fwhith, (int)_fHight); int errValue = 0; g.DrawImage(Encoding.Default.GetBytes(printPra.personPhoto), (int)X, (int)Y, (int)_fwhith, (int)_fHight, out errValue); return(true); }
// Printing on Both Sides --------------------------------------------------------------------------- public void PrintBothSides(string drvName, string frontText, string imgPath, string backText, out int jobID, out string msg) { jobID = 0; msg = string.Empty; int errValue; // value of 0 indicates no errors ZBRGraphics graphics = null; try { // Creates a Graphics Buffer graphics = new ZBRGraphics(); if (graphics.InitGraphics(ASCIIEncoding.ASCII.GetBytes(drvName), "job", out jobID, out errValue) == 0) { msg = "Printing InitGraphics Error: " + errValue.ToString(); return; } // Draws Text into the Graphics Buffer int fontStyle = FONT_BOLD | FONT_ITALIC | FONT_UNDERLINE | FONT_STRIKETHRU; if (graphics.DrawText(35, 575, ASCIIEncoding.ASCII.GetBytes(frontText), ASCIIEncoding.ASCII.GetBytes("Arial"), 12, fontStyle, 0xFF0000, out errValue) == 0) { msg = "Printing DrawText Error: " + errValue.ToString(); return; } // Draws a line into the Graphics Buffer if (graphics.DrawLine(35, 300, 300, 300, 0xFF0000, (float)5.0, out errValue) == 0) { msg = "Printing DrawLine Error: " + errValue.ToString(); return; } // Places an Image from a File into the Graphics Buffer if (graphics.DrawImage(ASCIIEncoding.ASCII.GetBytes(imgPath + "\\Zebra.bmp"), 30, 30, 200, 150, out errValue) == 0) { msg = "Printing DrawImage Error: " + errValue.ToString(); return; } // Sends Barcode Data to the Monochrome Buffer if (graphics.DrawBarcode(35, 500, 0, 0, 1, 3, 30, 1, ASCIIEncoding.ASCII.GetBytes("123456789"), out errValue) == 0) { msg = "Printing DrawBarcode Error: " + errValue.ToString(); return; } // Prints the Graphics Buffer (Front Side) if (graphics.PrintGraphics(out errValue) == 0) { msg = "Printing PrintGraphics Error: " + errValue.ToString(); return; } // Clears the Graphics Buffer if (graphics.ClearGraphics(out errValue) == 0) { msg = "Printing ClearGraphics Error: " + errValue.ToString(); return; } // Draws Text into the Graphics Buffer if (graphics.DrawText(30, 575, ASCIIEncoding.ASCII.GetBytes(backText), ASCIIEncoding.ASCII.GetBytes("Arial"), 12, fontStyle, 0, out errValue) == 0) { msg = "Printing DrawText Error: " + errValue.ToString(); return; } // Prints the Graphics Buffer (Back Side) if (graphics.PrintGraphics(out errValue) == 0) { msg = "Printing PrintGraphics Error: " + errValue.ToString(); return; } } catch (Exception ex) { msg += ex.ToString(); System.Windows.Forms.MessageBox.Show(ex.ToString(), "PrintBothSides"); } finally { if (graphics != null) { // Starts the printing process and releases the Graphics Buffer if (graphics.CloseGraphics(out errValue) == 0) { msg = "Printing CloseGraphics Error: " + errValue.ToString(); } graphics = null; } } }