Convert png file to pcx file using c #

I am trying to convert a .png file to a .pcx file. The scenario is as follows:

I am using a TSC TTP-343C label printer. I have to print images on the labels. TSC provides library documentation for developers. Since I can only print images on these labels using pcx files, I need to convert all the images to pcx images. Any other format or even the wrong pcx format (for example, if the user simply renamed the end of the file) will not be printed on the label.

I saw this post related to the Magick library. In this post, the OP is trying to convert the bmp file to a pcx file, which is not quite what I am trying to achieve. I looked at the Magick documentation on image conversion . I tried to convert images, for example:

 using (MagickImage img = new MagickImage(png)) // png is a string containing the path of the .png file { img.Format = MagickFormat.Pcx; img.Write(pcx); // pcx is a string containing the path of the new .pcx file } 

Unfortunately, this does not save the image correctly. The label printer still cannot print the image on the label. I tried to print the correct pcx file and it worked fine. Therefore, I assume that the only reason it still does not work is because the converted file is not a real pcx file.

Is there any way to do such a conversion? If so, how can I achieve this? My application is a Windows Form application written in C # using the .NET framework 4.5.2.

EDIT:

Here you can see an example of how to print a label with a pcx file:

 TSC.openport(sPrinterName); TSC.setup("100", "100", "4", "8", "1", "3.42", "0"); TSC.clearbuffer(); TSC.downloadpcx(@"\\PathToPcxFile\test.pcx", "test.pcx"); TSC.sendcommand("PUTPCX 35," + y + ",\"test.pcx\""); TSC.printlabel("1", "1"); TSC.closeport(); 

This code works fine on real pcx files. TSC library methods can be found here .

downloadpcx (a, b)

Description: Download mono PCX image files to the printer Parameter:

a: string; file name (including file search path)

b: string, the names of the files to be loaded into (use capital letters)

Source: http://www.tscprinters.com/cms/upload/download_en/DLL_instruction.pdf

EDIT II:

The pcx file that works (created using Photoshop) looks like this (if that helps you):

enter image description here

+5
source share
1 answer

PCX files (at best) based on a palette.

So, to create the correct pcx output, you need to add this line:

 using (MagickImage image = new MagickImage(sourcePng)) { image.Format = MagickFormat.Pcx; image.ColorType = ColorType.Palette; // <---- image.Write(targetPcx); } 

Your image as a pcx file

+6
source

Source: https://habr.com/ru/post/1244370/


All Articles