Click or drag to resize

ZebraGraphics Interface

Interface for Zebra card printer graphics.

Namespace:  Zebra.Sdk.Card.Graphics
Assembly:  SdkApi_Card_Desktop (in SdkApi_Card_Desktop.dll) Version: 2.14.1989
Syntax
public interface ZebraGraphics : ZebraGraphicsI, 
	IDisposable

The ZebraGraphics type exposes the following members.

Properties
  NameDescription
Public propertyBrightnessLevel
Sets the brightness correction level to be applied during CreateImage.
(Inherited from ZebraGraphicsI.)
Public propertyContrastLevel
Sets the contrast correction level to be applied during CreateImage.
(Inherited from ZebraGraphicsI.)
Public propertyGammaLevel
Sets the gamma correction level to be applied during CreateImage.
(Inherited from ZebraGraphicsI.)
Public propertyMonochromeConverionType
Gets or Sets the monochrome conversion type to be used during CreateImage.
(Inherited from ZebraGraphicsI.)
Public propertyPrinterModel
Gets or Sets the printer model for use when creating or processing graphic images.
(Inherited from ZebraGraphicsI.)
Public propertySaturationLevel (Inherited from ZebraGraphicsI.)
Public propertySmoothingMode
Gets or sets the quality of the graphics rendering.
Public propertyTextContrast
Gets or sets the gamma correction level used for rendering text.
Public propertyTextRenderingHint
Gets or sets the quality of the text rendering.
Top
Methods
  NameDescription
Public methodClear
Clears the drawing surface and all user specified parameters.
(Inherited from ZebraGraphicsI.)
Public methodClose
Releases all resources.
(Inherited from ZebraGraphicsI.)
Public methodCreateImage
Generates the final bitmap image.
(Inherited from ZebraGraphicsI.)
Public methodCreateImage(String)
Generates the final bitmap image.
Public methodCropImage
Crops an image to the supplied dimensions.
(Inherited from ZebraGraphicsI.)
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from IDisposable.)
Public methodDrawEllipse
Draws an ellipse at the specified coordinates.
Public methodDrawImage(Byte, Int32, Int32, Int32, Int32, RotationType)
Draws the image into the specified rectangle.
(Inherited from ZebraGraphicsI.)
Public methodDrawImage(Byte, ImagePosition, Int32, Int32, Single, RotationType)
Draws the image at the specified image position in the rectangle.
(Inherited from ZebraGraphicsI.)
Public methodDrawImage(Byte, Int32, Int32, Int32, Int32, Single, RotationType)
Draws the image into the specified rectangle.
(Inherited from ZebraGraphicsI.)
Public methodDrawLine
Draws a line from/to the specified coordinates.
Public methodDrawRectangle
Draws a rectangle at the specified coordinates.
Public methodDrawRoundedRectangle
Draws a round-cornered rectangle at the specified coordinates.
Public methodDrawText(String, Font, Color, Int32, Int32)
Draws the text at the specified x and y coordinates.
Public methodDrawText(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.
Public methodDrawText(String, Font, Color, Int32, Int32, Int32, Int32, Int32)
Draws the text into the specified rectangle.
Public methodDrawText(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.
Public methodDrawText(String, Font, Color, Int32, Int32, Int32, Int32, Int32, TextAlignment, TextAlignment)
Draws the text into the specified rectangle using the specified alignments.
Public methodDrawText(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.
Public methodExtractBlackImageData
Separates the monochrome and color data from the specified image data using the specified threshold values.
(Inherited from ZebraGraphicsI.)
Public methodExtractHalfPanelImageData
Attempts to identify and extract the color and non-color half panel regions of the source image.
(Inherited from ZebraGraphicsI.)
Public methodImageDataToImage
Converts image data to an Image object.
Public methodImageToImageData
Converts an image to a byte array.
Public methodInitialize(Int32, Int32, OrientationType, PrintType, NullableColor)
Initializes the drawing surface.
Public methodInitialize(Int32, Int32, OrientationType, PrintType, NullableInt32)
Initializes the drawing surface.
(Inherited from ZebraGraphicsI.)
Public methodRotateImage(Byte, RotationType)
Rotates the image by the specified rotationType.
(Inherited from ZebraGraphicsI.)
Public methodRotateImage(Byte, Int32, Int32, RotationType)
Rotates the image by the specified rotationType and then resizes it.
(Inherited from ZebraGraphicsI.)
Public methodSetColorScale
Sets the color scale correction values for red, green, and blue pixel values during CreateImage.
(Inherited from ZebraGraphicsI.)
Top
Examples
Demonstrates how to print graphics objects utilizing the color, mono, and overlay ribbon panels.
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
}
See Also