
G.RotateTransform(angle) // set up rotate G.TranslateTransform(originX, originY) // offset the origin to our calculated values New (( int)newImgWidth, ( int)newImgHeight) OriginX = newImgWidth - sin * bmp.Height 0)) // this one too float newImgWidth = sin * bmp.Height + cos * bmp.Width įloat newImgHeight = sin * bmp.Width + cos * bmp.Height 0)) // this function takes radians float cos = ( float)Math.Abs(Math.Cos(angle * Math.PI / 180. Private static RotateImgįloat sin = ( float)Math.Abs(Math.Sin(angle * I post here together so if someone is interested, there is no need to Google. I found this function on the internet, I just edited to suit my purpose.

get encoding, I have no idea why encode page of 1252 works and fails for others return Encoding.GetEncoding( 1252).GetString(ms.ToArray()) Now we convert image into 2 dimension binary matrix by 2 for loops below, // in the range of image, we get colour of pixel of image, // calculate the luminance in order to set value of 1 or 0 // otherwise we set value to 1 // Because P3 is set to byte (8 bits), so we gather 8 dots of this matrix, // convert into a byte then write it to memory by using shift left operator 10000000 // 1 01000000 // 1 00001000 for ( int y = 0 y 127 ? 1 : 0 Ībyte |= ( byte)(dot << ( 7 - b)) // shift left, // then OR together to get 8 bits into a byte the width of matrix is rounded up multi of 8 int canvasWidth = P3 * 8 ( " GW,", top, left, P3, bitmap.Height))) we set p3 parameter, remember it is Width of Graphic in bytes, // so we divive the width of image and round up of it int P3 = ( int)Math.Ceiling(( double)bitmap.Width / 8) īw.Write(( string.Format Using (BinaryWriter bw = new BinaryWriter(ms, Encoding.ASCII)) Using (MemoryStream ms = new MemoryStream()) Private static string SendImageToPrinter( int top, int left, bitmap) First, we create a function wrapping GW command and return a string: We will use the SendStringToPrinter of RawPrinterHelper.cs to send data to Zebra printer.
#Zpl rotate image from memory code#
The attached code is built using C# 2008. So we have to convert an image into 2 dimension binary matrix as below and add extra bits to make up the width of matrix which is multi of 8 bits 40 pixels round up to multi of 8

In order to show the DATA I mention above, let's say we have a image with 35 x 5 pixels.īecause Zebra printer prints image on black & white colours only, black (burned) presenting by bit 0 and white (not burned) presenting by bit 1.

I start downloading epl2_programming.pdf and read through it.įirst, I found out the code of EPL is not hard to learn, so I start coding with the text, barcode, box, line, etc.īut, hmm., with image is not simple as I imagine. When a new project comes, I decide to create my own way to print texts and images to Zebra printer. In the past, I used the to help to do so. My job involves printing texts and images on Zebra labels. In this tip, we shall see how C# can print image to Zebra printer using RawPrinterHelper class from Microsoft.
