title: convert a png file to a pcx file using c#
body: <p>I'm trying to convert a <code>.png</code> file to a <code>.pcx</code> file. The scenario is the following:</p>
  <p>I'm using a TSC TTP-343C label printer. On the labels I have to print images. TSC provides a <a href="http://www.tscprinters.com/cms/upload/download_en/DLL_instruction.pdf" rel="nofollow noreferrer">library documentation</a> for developers. Since I can only print images on those labels using pcx files I have to convert all the images to pcx images. Any other format or even incorrect pcx format (e.g. if the user just renamed the file ending) will not be printed on the label.</p>
  <p>I've seen <a href="https://stackoverflow.com/questions/21035662/how-to-convert-bmp-file-to-pcx-file">this post</a> linking to the <code>Magick</code> library. In this post, the OP is trying to convert a bmp file to a pcx file which is not exactly what I try to achieve. I looked at the <code>Magick</code> <a href="http://magick.codeplex.com/documentation?referringTitle=Home" rel="nofollow noreferrer">documentation</a> about <a href="http://magick.codeplex.com/wikipage?title=Convert%20image&amp;referringTitle=Documentation" rel="nofollow noreferrer">converting images</a>. I tried to convert the images like:</p>
  <pre><code>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
  }
  </code></pre>
  <p>Unfortunately this is not saving the image correctly. The label printer still cannot print the image on the label. I tried printing a correct pcx file and this worked fine. So I guess the only reason why it's still not working is that the converted file is not a real pcx file.</p>
  <p>Is there a way to do such a conversion? If yes, how can I achieve that? My application is a windows forms application, written in C# using .NET framework 4.5.2.</p>
  <p><strong>EDIT:</strong></p>
  <p>Here you can see an example how to print a label with a pcx file:</p>
  <pre><code>TSC.openport(sPrinterName);
  TSC.setup(&quot;100&quot;, &quot;100&quot;, &quot;4&quot;, &quot;8&quot;, &quot;1&quot;, &quot;3.42&quot;, &quot;0&quot;);
  TSC.clearbuffer();
  
  TSC.downloadpcx(@&quot;\\PathToPcxFile\test.pcx&quot;, &quot;test.pcx&quot;);
  TSC.sendcommand(&quot;PUTPCX 35,&quot; + y + &quot;,\&quot;test.pcx\&quot;&quot;);
  
  TSC.printlabel(&quot;1&quot;, &quot;1&quot;);
  TSC.closeport();
  </code></pre>
  <p>This code works fine on real pcx files. The methods of the TSC library can you find <a href="http://www.tscprinters.com/cms/upload/download_en/DLL_instruction.pdf" rel="nofollow noreferrer">here</a>.</p>
  <blockquote>
  <p><strong>downloadpcx(a,b)</strong></p>
  <p>Description: Download mono PCX graphic files to the printer Parameter:</p>
  <p>a: string; file name (including file retrieval
  path)</p>
  <p>b: string, names of files that are to be downloaded in the
  printer memory (Please use capital letters)</p>
  <p>Source: <a href="http://www.tscprinters.com/cms/upload/download_en/DLL_instruction.pdf" rel="nofollow noreferrer">http://www.tscprinters.com/cms/upload/download_en/DLL_instruction.pdf</a></p>
  </blockquote>
  <p><strong>EDIT II:</strong></p>
  <p>A pcx file which is working (created using photoshop) looks like this (if it helps you):</p>
  <p><a href="https://i.stack.imgur.com/DTFR9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTFR9.png" alt="enter image description here" /></a></p>