【问题标题】:Convert EPS to JPG on upload using C# and ImageMagick使用 C# 和 ImageMagick 在上传时将 EPS 转换为 JPG
【发布时间】:2011-08-27 05:04:58
【问题描述】:

我刚刚遇到一个场景,我需要在上传时将 EPS 文件转换为 JPG 文件。

在上传 EPS 文件时,我更愿意做的是;我想保留原始EPS文件并将其保存在一个文件夹下的背景中,并将EPS图像转换为JPG并将其保存在另一个文件夹中。

这是可以使用 C# 实现的吗?如果是这样,有人可以指导我正确的方向吗?

我使用过 ImageMagick 和 GhostScript,我可以从命令行将 EPS 转换为 JPG,但不确定如何将其嵌入 C# 应用程序并在上传时将 EPS 转换为 JPG。

任何帮助或任何演示都将是一个很大的帮助。

谢谢, 祖尔菲

【问题讨论】:

标签: c# asp.net image-processing imagemagick


【解决方案1】:

老实说,您可以考虑自己解析 EPS 文件。

您可能可以在网上找到各种文件格式信息,例如 wotsit.org(自 90 年代就已经存在,那时人们仍然从头开始编写他们需要的内容。)

这样做的好处是不需要将外部工件嵌入到您的解决方案中,也不会产生许可费用。它显然有个人时间投资于研发的缺点。之后,也许您可​​以与其他人共享您的代码/库,而无需支付归属、版权或许可费用。

祝你好运!

【讨论】:

    【解决方案2】:

    在研究了一段时间可用的解决方案后,我发现this utility 似乎运作良好。它是 200 美元/服务器。 VeryDoc 的实用程序不依赖任何第三方库(与其他解决方案不同),它提供多种格式之间的转换。可用的命令行选项:

    C:\>ps2img.exe
    -------------------------------------------------------
    Description:
    Convert PS (Postscript) and EPS to TIF, TIFF, JPG, GIF, PNG, BMP, WMF, EMF, PCX, TGA, etc. formats
    Usage: ps2img [options] <-i PS File> [-o Output]
    -i [input PS]   : Input PS filename
    -o [output file]: Output TIFF filename
    -g              : Convert to 8-bit grayscale image file, this option is only available while bitcount equal 8 (-b 8)
    -m              : Set output to multi-page TIFF file, the default is output to single page TIFF files
    -r [resolution] : Set resolution in generated image files
    -r 300          : Set horizontal and vertical resolution to 300 DPI
    -r 200x300      : Set horizontal and vertical resolution to 200x300 DPI
    -r 204x98       : Set horizontal and vertical resolution to 204x98 DPI
    -f [first Page] : First page to convert
    -l [last Page]  : Last page to convert
    -c [compress]   : Set compression method in generated image files (for tif only)
        -c none     : Create TIFF file without compression
        -c lzw      : Compress TIFF using LZW arithmetic
        -c jpeg     : Compress TIFF using JPEG arithmetic
        -c packbits : Compress TIFF using packbits arithmetic
        -c g3       : Compress TIFF using CCITT G3 arithmetic
        -c g4       : Compress TIFF using CCITT G4 arithmetic
        -c ClassF   : Compress TIFF into Fax compatible ClassF 204x98 format
        -c ClassF196: Compress TIFF into Fax compatible ClassF 204x196 format
    -q [quality]    : Set quality in created image files (for jpeg image only)
    -b [bit count]  : Set bit count in generated image files
    -?              : Help
    -------------------------------------------------------
    Example:
        ps2img -i C:\input.ps -o C:\output.tif
        ps2img -i C:\input.eps -o C:\output.tif
        ps2img -m -i C:\input.ps -o C:\output.tif
        ps2img -c lzw -i C:\input.ps -o C:\output.tif
        ps2img -q 80 -i C:\input.ps -o C:\output.jpg
        ps2img -b 4 -i C:\input.ps -o C:\output.tif
        ps2img -i C:\input.ps -o C:\output.tif -b 1 -c ClassF -r 204x98 -m
        ps2img -f 1 -l 9 C:\input.ps -o C:\output.jpg
        ps2img -i C:\*.ps -o C:\*.pcx
    

    另一种选择,ImageMagick(免费)+ GhostScript 是 reportedly,每年 32,000 美元以上 + 5,000 美元的安装费。

    【讨论】:

    • @ShaunWilson 是的,当我看到那个价格标签时,我真的很惊讶。与另外一两个团队合作并创建内部解决方案比每年支付 100,000 美元更经济。我也很惊讶地遇到了一个售价 200 美元的实用程序。我想功能集与 ghostscript 相比是有限的,但它可以满足我的需要。也许 GS 应该将他们的库分成单独的块并单独许可。
    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    • @rgettman 我试图在我的回答中提供更多信息,尽管我不确定链接之外的信息有多大用处。
    【解决方案3】:

    通过这个使用ImageMagickNET.dll,您可以将.eps、.ai、.psd、.tga 文件转换为.jpg 格式。 c#代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using SimplePsd;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Media;
    using System.DirectoryServices;
    using System.Diagnostics;
    namespace Master_Graphics
    {
        public partial class Form1 : Form
        { 
    
            private SimplePsd.CPSD psd = new SimplePsd.CPSD();
            Process ffmpeg;
            string video;
            string thumb;
            public Form1()
            {
                InitializeComponent();
            }
     private void button4_Click(object sender, EventArgs e)
            {
    ffmpeg = new Process();
                    ffmpeg.StartInfo.Arguments = "convert \"" + listBox1.SelectedItem.ToString() + "\" -background white -flatten -density 300 -colors 512 -antialias  -normalize -units PixelsPerInch -quality 100 -colorspace RGB -resize 3425x3425  \"D:\\GRAPHICS SEARCH ENGINE\\GRAPHICS IMAGES\\EPS\\" + final + ".jpg\"";
                    ffmpeg.StartInfo.FileName = ("C:\\Program Files (x86)\\ImageMagick-6.5.3-Q16\\convert.exe");
                    ffmpeg.Start();
    }
    

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      • 2012-11-21
      • 2014-11-02
      相关资源
      最近更新 更多