6 Replies Latest reply on Jan 29, 2018 7:49 PM by Matthew Belk

    Image Conversion Error on iOS printing a PNG file using IZebraPrinter.PrintImage

    Matthew Belk

      I am trying to print a PNG signature image using CPCL on a QLn420 using the LinkOS SDK for Xamarin on an iPhone. I can print the text part of the receipt using line print mode beautifully, but when I get to the point where I need to print my image, I get the following exception from the printer object:


      Error - Error MSG: Error printing receipt | Exception: LinkOS.Plugin.ConnectionException: Image conversion error: Error writing to connection   at LinkOS.Plugin.ZebraPrinterImplementation.PrintImage (System.Object os_image, System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height, System.Boolean insideFormat) [0x00041] in <5ba493cd13a6476cb6f38f54ba338afd>:0 


      The code I am using to attempt to print this image is this:


                private void PrintImage(IConnection connection, byte[] imageSource, int x, int y) {              var provider = new CGDataProvider(NSData.FromArray(imageSource));              var png = CGImage.FromPNG(provider, null, false, CGColorRenderingIntent.Default);                PrintImage(connection, png, x, y);          }            private void PrintImage(IConnection connection, CGImage zebraBitmap, int x, int y)          {              try {                  connection.TimeToWaitAfterWrite = 200;                    if (!connection.IsConnected)                      connection.Open();                    #region SignatureImage                  var printer = ZebraPrinterFactory.Current.GetInstance(PrinterLanguage.CPCL, connection);                  connection.Write(GetBytes("! U1 setvar \"device.languages\" \"cpcl\"\r\n"));                    printer.PrintImage(zebraBitmap, x, y, Convert.ToInt32(zebraBitmap.Width), Convert.ToInt32(zebraBitmap.Height), true);                  Thread.Sleep(3000);                    #endregion              }              finally {                  connection.Write(GetBytes("\r\n"));                  connection.Write(GetBytes("! U1 setvar \"device.languages\" \"line_print\"\r\n"));              }          }


      This exact same code on the exact same printer works like a champ in my Android platform project.


      Any help or suggestions would be most appreciated.




        • Re: Image Conversion Error on iOS printing a PNG file using IZebraPrinter.PrintImage
          Robin West

          Hi Matthew,

          I don't see anything specifically wrong with your code

          Is your imageSource a standard, non-compressed or encoded, png? This system assumes it is standard.

          Here is my code for getting the CGImage in iOS, it does assume the image is already saved as a file, but your provider should also work:


                  public object GetImage(string fileName)
                      CGImage image = null;
                      fileName = fileName + ".png";
                      image = new CGImage(400, 200, 1, 1, 400, CGColorSpace.CreateGenericRgbLinear(), CGBitmapFlags.First, CGDataProvider.FromFile(fileName), null, false, CGColorRenderingIntent.Default);
                      return image;


          It looks fairly similar, but try it.