ZebraGraphics Interface |
Namespace: Zebra.Sdk.Card.Graphics
The ZebraGraphics type exposes the following members.
Name | Description | |
---|---|---|
BrightnessLevel |
Sets the brightness correction level to be applied during CreateImage.
(Inherited from ZebraGraphicsI.) | |
ContrastLevel |
Sets the contrast correction level to be applied during CreateImage.
(Inherited from ZebraGraphicsI.) | |
GammaLevel |
Sets the gamma correction level to be applied during CreateImage.
(Inherited from ZebraGraphicsI.) | |
MonochromeConverionType |
Gets or Sets the monochrome conversion type to be used during CreateImage.
(Inherited from ZebraGraphicsI.) | |
PrinterModel |
Gets or Sets the printer model for use when creating or processing graphic images.
(Inherited from ZebraGraphicsI.) | |
SaturationLevel |
Sets the saturation level to be applied during CreateImage.
(Inherited from ZebraGraphicsI.) | |
SmoothingMode |
Gets or sets the quality of the graphics rendering.
| |
TextContrast |
Gets or sets the gamma correction level used for rendering text.
| |
TextRenderingHint |
Gets or sets the quality of the text rendering.
|
Name | Description | |
---|---|---|
Clear |
Clears the drawing surface and all user specified parameters.
(Inherited from ZebraGraphicsI.) | |
Close |
Releases all resources.
(Inherited from ZebraGraphicsI.) | |
CreateImage |
Generates the final bitmap image.
(Inherited from ZebraGraphicsI.) | |
CreateImage(String) |
Generates the final bitmap image.
| |
CropImage |
Crops an image to the supplied dimensions.
(Inherited from ZebraGraphicsI.) | |
Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.) | |
DrawEllipse |
Draws an ellipse at the specified coordinates.
| |
DrawImage(Byte, Int32, Int32, Int32, Int32, RotationType) |
Draws the image into the specified rectangle.
(Inherited from ZebraGraphicsI.) | |
DrawImage(Byte, ImagePosition, Int32, Int32, Single, RotationType) |
Draws the image at the specified image position in the rectangle.
(Inherited from ZebraGraphicsI.) | |
DrawImage(Byte, Int32, Int32, Int32, Int32, Single, RotationType) |
Draws the image into the specified rectangle.
(Inherited from ZebraGraphicsI.) | |
DrawLine |
Draws a line from/to the specified coordinates.
| |
DrawRectangle |
Draws a rectangle at the specified coordinates.
| |
DrawRoundedRectangle |
Draws a round-cornered rectangle at the specified coordinates.
| |
DrawText(String, Font, Color, Int32, Int32) |
Draws the text at the specified x and y coordinates.
| |
DrawText(String, Font, Color, Int32, Int32, Int32) |
Draws the text at the specified x and y coordinates and center rotates the text to the specified angle.
| |
DrawText(String, Font, Color, Int32, Int32, Int32, Int32, Int32) |
Draws the text into the specified rectangle.
| |
DrawText(String, Font, Color, Int32, Int32, Int32, Int32, Int32, Boolean) |
Draws the text into the specified rectangle, optionally reducing the size of the font to fit the specified rectangle.
| |
DrawText(String, Font, Color, Int32, Int32, Int32, Int32, Int32, TextAlignment, TextAlignment) |
Draws the text into the specified rectangle using the specified alignments.
| |
DrawText(String, Font, Color, Int32, Int32, Int32, Int32, Int32, TextAlignment, TextAlignment, Boolean) |
Draws the text into the specified rectangle using the specified alignments, optionally reducing the size of the font to fit the specified rectangle.
| |
ExtractBlackImageData |
Separates the monochrome and color data from the specified image data using the specified threshold values.
(Inherited from ZebraGraphicsI.) | |
ExtractHalfPanelImageData |
Attempts to identify and extract the color and non-color half panel regions of the source image.
(Inherited from ZebraGraphicsI.) | |
ImageDataToImage |
Converts image data to an Image object.
| |
ImageToImageData |
Converts an image to a byte array.
| |
Initialize(Int32, Int32, OrientationType, PrintType, NullableColor) |
Initializes the drawing surface.
| |
Initialize(Int32, Int32, OrientationType, PrintType, NullableInt32) |
Initializes the drawing surface.
(Inherited from ZebraGraphicsI.) | |
RotateImage(Byte, RotationType) |
Rotates the image by the specified rotationType.
(Inherited from ZebraGraphicsI.) | |
RotateImage(Byte, Int32, Int32, RotationType) |
Rotates the image by the specified rotationType and then resizes it.
(Inherited from ZebraGraphicsI.) | |
SetColorScale |
Sets the color scale correction values for red, green, and blue pixel values during CreateImage.
(Inherited from ZebraGraphicsI.) |
using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Threading; using Zebra.Sdk.Card.Containers; using Zebra.Sdk.Card.Enumerations; using Zebra.Sdk.Card.Graphics; using Zebra.Sdk.Card.Graphics.Barcode; using Zebra.Sdk.Card.Graphics.Enumerations; using Zebra.Sdk.Card.Printer; using Zebra.Sdk.Comm; public class PrintGraphicsExample { private const int CARD_FEED_TIMEOUT = 30000; public static void Main(string[] args) { Connection connection = null; ZebraCardPrinter zebraCardPrinter = null; try { connection = new UsbConnection("\\\\?\\usb#vid_0a5f&pid_00a7#411738706#..."); connection.Open(); zebraCardPrinter = ZebraCardPrinterFactory.GetInstance(connection); List<GraphicsInfo> graphicsData = DrawGraphics(zebraCardPrinter); // Send job and poll for status int jobId = zebraCardPrinter.Print(1, graphicsData); JobStatusInfo jobStatus = PollJobStatus(jobId, zebraCardPrinter); Console.WriteLine($"Job {jobId} completed with status '{jobStatus.PrintStatus}'."); } catch (Exception e) { Console.WriteLine($"Error printing graphics: {e.Message}"); } finally { CloseQuietly(connection, zebraCardPrinter); } } - #region Graphics /// <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 static List<GraphicsInfo> DrawGraphics(ZebraCardPrinter zebraCardPrinter) { List<GraphicsInfo> graphicsData = new List<GraphicsInfo>(); using (ZebraGraphics graphics = new ZebraCardGraphics(zebraCardPrinter)) { graphicsData.Add(DrawColorImage(graphics, CardSide.Front)); graphicsData.Add(DrawMonoImage(graphics, CardSide.Front)); graphicsData.Add(DrawOverlayImage(graphics, CardSide.Front)); } return graphicsData; } /// <exception cref="Zebra.Sdk.Card.Exceptions.ZebraCardException"></exception> /// <exception cref="Zebra.Sdk.Device.ZebraIllegalArgumentException"></exception> private static GraphicsInfo DrawColorImage(ZebraGraphics graphics, CardSide side) { // Color Rectangle and Line - front try { graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.Color, null); graphics.DrawRectangle(200, 50, 200, 100, 5, Color.Red, null); graphics.DrawRoundedRectangle(500, 50, 200, 100, 20, 5, Color.Gray, null); graphics.DrawLine(new PointF(200, 200), new PointF(700, 200), 5, Color.Blue); ZebraCardImageI zebraCardImage = graphics.CreateImage(); return AddImage(side, PrintType.Color, 0, 0, -1, zebraCardImage); } finally { graphics.Clear(); } } /// <exception cref="Zebra.Sdk.Card.Exceptions.ZebraCardException"></exception> /// <exception cref="Zebra.Sdk.Device.ZebraIllegalArgumentException"></exception> private static GraphicsInfo DrawMonoImage(ZebraGraphics graphics, CardSide side) { try { // Mono Text and Barcode - front graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.MonoK, null); using (Font font = new Font("Arial", 12)) { graphics.DrawText("Zebra Technologies", font, Color.Black, 200, 250); } using (QRCodeUtil qrCode = ZebraBarcodeFactory.GetQRCode(graphics)) { qrCode.ValueToEncode = "https://www.zebra.com"; qrCode.DrawBarcode(675, 240, 75, 75); } ZebraCardImageI zebraCardImage = graphics.CreateImage(); return AddImage(side, PrintType.MonoK, 0, 0, -1, zebraCardImage); } finally { graphics.Clear(); } } /// <exception cref="ArgumentException"></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 static GraphicsInfo DrawOverlayImage(ZebraGraphics graphics, CardSide side) { try { // Overlay Image - front graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.Overlay, null); string overlayImagePath = @"path\to\myOverlayImage.bmp"; byte[] imageData = File.ReadAllBytes(overlayImagePath); graphics.DrawImage(imageData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone); ZebraCardImageI zebraCardImage = graphics.CreateImage(); return AddImage(side, PrintType.Overlay, 0, 0, -1, zebraCardImage); } finally { graphics.Clear(); } } private static GraphicsInfo AddImage(CardSide side, PrintType printType, int xOffset, int yOffset, int fillColor, ZebraCardImageI zebraCardImage) { return new GraphicsInfo { Side = side, PrintType = printType, GraphicType = zebraCardImage != null ? GraphicType.BMP : GraphicType.NA, XOffset = xOffset, YOffset = yOffset, FillColor = fillColor, Opacity = 0, Overprint = false, GraphicData = zebraCardImage ?? null }; } #endregion Graphics - #region JobStatus /// <exception cref="ArgumentException"></exception> /// <exception cref="ConnectionException"></exception> /// <exception cref="IOException"></exception> /// <exception cref="OverflowException"></exception> /// <exception cref="Zebra.Sdk.Settings.SettingsException"></exception> /// <exception cref="Zebra.Sdk.Card.Exceptions.ZebraCardException"></exception> private static JobStatusInfo PollJobStatus(int jobId, ZebraCardPrinter zebraCardPrinter) { JobStatusInfo jobStatusInfo = new JobStatusInfo(); bool isFeeding = false; long start = Math.Abs(Environment.TickCount); while (true) { jobStatusInfo = zebraCardPrinter.GetJobStatus(jobId); if (!isFeeding) { start = Math.Abs(Environment.TickCount); } isFeeding = jobStatusInfo.CardPosition.Contains("feeding"); string alarmDesc = jobStatusInfo.AlarmInfo.Value > 0 ? $" ({jobStatusInfo.AlarmInfo.Description})" : ""; string errorDesc = jobStatusInfo.ErrorInfo.Value > 0 ? $" ({jobStatusInfo.ErrorInfo.Description})" : ""; Console.WriteLine($"Job {jobId}: status:{jobStatusInfo.PrintStatus}, position:{jobStatusInfo.CardPosition}, alarm:{jobStatusInfo.AlarmInfo.Value}{alarmDesc}, error:{jobStatusInfo.ErrorInfo.Value}{errorDesc}"); if (jobStatusInfo.PrintStatus.Contains("done_ok")) { break; } else if (jobStatusInfo.PrintStatus.Contains("error") || jobStatusInfo.PrintStatus.Contains("cancelled")) { Console.WriteLine($"The job encountered an error [{jobStatusInfo.ErrorInfo.Description}] and was cancelled."); break; } else if (jobStatusInfo.ErrorInfo.Value > 0) { Console.WriteLine($"The job encountered an error [{jobStatusInfo.ErrorInfo.Description}] and was cancelled."); zebraCardPrinter.Cancel(jobId); } else if (jobStatusInfo.PrintStatus.Contains("in_progress") && isFeeding) { if (Math.Abs(Environment.TickCount) > start + CARD_FEED_TIMEOUT) { Console.WriteLine("The job timed out waiting for a card and was cancelled."); zebraCardPrinter.Cancel(jobId); } } Thread.Sleep(1000); } return jobStatusInfo; } #endregion JobStatus - #region CleanUp private static void CloseQuietly(Connection connection, ZebraCardPrinter zebraCardPrinter) { try { if (zebraCardPrinter != null) { zebraCardPrinter.Destroy(); } } catch { } try { if (connection != null) { connection.Close(); } } catch { } } #endregion CleanUp }