BinaryKits / BinaryKits.Zpl

BinaryKits.Zpl a set of .net libraries. The project supports you in the simple creation of zebra labels. It generates the ZPL data, it is a printer description language from Zebra Technologies. ZPL II is now emulated by many label printers from different manufacturers. So with this implementation you can create labels for most printers.
MIT License
312 stars 112 forks source link

Adding images to ZPL #2

Closed Karthik-Nagendiran closed 6 years ago

Karthik-Nagendiran commented 7 years ago

Hi, How do I add an Image (base64 encoded string) to the ZPL using your utility ? Basically the scenario is like, the user will upload an image and I will convert them to base64 encoded string and that image needs to be printed through ZPL commands on the label. Any suggestions ? thanks, Karthik. N

YipingRuan commented 7 years ago

Thanks for your feedback. At this moment you need to prepare the raw ZPL code: renderEngine.Add(new ZPLRaw("~DGd:o.x,t,w,data"));

I am thinking a good way to allow jpg image directly, do you have any suggestions?

Karthik-Nagendiran commented 7 years ago

I'm currently using ~DYE command to process the Image data. Converting the image data to Bytes and then to ASCII HEX. But sometimes it is taking too much of time for the conversion. Looking for better alternatives.

YipingRuan commented 7 years ago

How about something like this: http://www.jcgonzalez.com/zpl-ascii-hex-representation-image-generator

Given an stream (System.Drawing.Bitmap) and monochrome ZPL code is generated.

YipingRuan commented 7 years ago

Try the new commit https://github.com/BinaryKits/ZPLUtility/commit/519c89f21868edec9c1c4a5da3b0f4625d17dafb

Karthik-Nagendiran commented 7 years ago

Thanks for the update. Anyway to disable the scaling of image alone when I give source and target DPI.

YipingRuan commented 7 years ago

Do you mean the physical dimensions on the label should remain the same regardless of dpi?

Karthik-Nagendiran commented 7 years ago

Yes, When I tried your code to process the image, after scaling the image size seems to be bigger whereas the texts are scaled properly and fitting into the Label dimension.

Karthik-Nagendiran commented 7 years ago

How can I convert the image to Gray scale instead of Black and White ? Because converting it to Black and White loses the image quality and the contents are also not clear.

YipingRuan commented 7 years ago

@Karthik-Nagendiran Regarding the scaling issue, I tried on the http://labelary.com/viewer.html, seems to be consistent. Please check the "Print Density" drowdown on the page is matching your "TargetPrintDPI" setting in code?

YipingRuan commented 6 years ago

Due to the nature of ZPL printer (black and white dots only, no gray scale), we need to apply "Halftone" or "Dithering" to the original image. http://paint.net.amihotornot.com.au/Features/Effects/Plugins/Render/Dither/

This is an image process issue and should be done in Photoshop or Paint.net, as it requires many parameters.