title: How to generate a dynamic GRF image to ZPL ZEBRA print
body: <p>I have a problem.</p>
  
  <p>I´m generating a dynamic BMP image and trying to send this to a ZEBRA printer by ZPL commands.
  I need to convert my BMP to a GRF image. I think that my Hexadecimal extracted by the BMP image isn´t correct.</p>
  
  <p>The printed image is blurred and incorrect.</p>
  
  <p>This is my code:</p>
  
  <pre><code>string bitmapFilePath = @oldArquivo;  // file is attached to this support article
  byte[] bitmapFileData = System.IO.File.ReadAllBytes(bitmapFilePath);
  int fileSize = bitmapFileData.Length;
  
  Bitmap ImgTemp = new Bitmap(bitmapFilePath);
  Size ImgSize = ImgTemp.Size;
  ImgTemp.Dispose();
  
  // The following is known about test.bmp.  It is up to the developer
  // to determine this information for bitmaps besides the given test.bmp.            
  int width = ImgSize.Width;
  int height = ImgSize.Height;
  int bitmapDataOffset = 62; // 62 = header of the image
  int bitmapDataLength = fileSize - 62;// 8160;    
  
  double widthInBytes = Math.Ceiling(width / 8.0);    
  
  // Copy over the actual bitmap data from the bitmap file.
  // This represents the bitmap data without the header information.
  byte[] bitmap = new byte[bitmapDataLength];
  Buffer.BlockCopy(bitmapFileData, bitmapDataOffset, bitmap, 0, (bitmapDataLength));
  
  // Invert bitmap colors
  for (int i = 0; i &lt; bitmapDataLength; i++)
  {
      bitmap[i] ^= 0xFF;
  }
  
  // Create ASCII ZPL string of hexadecimal bitmap data
  string ZPLImageDataString = BitConverter.ToString(bitmap).Replace("-", string.Empty);
  
  string comandoCompleto = "~DG" + nomeImagem + ".GRF,0" + bitmapDataLength.ToString() + ",0" + widthInBytes.ToString() + "," + ZPLImageDataString;
  </code></pre>