图像处理控件Aspose.Imaging最新版功能亮点示例详解

  Aspose.Imaging for .NET一种高级图像处理控件,允许开发人员创建,编辑,绘制或转换图像。图像导出和转换是API核心功能之一,它允许在不安装Photoshop应用程序或任何其他图像编辑器的情况下保存为AdobePhotoshop?本机格式。

  近期发布了Aspose.Imaging for .NET v19.7,支持PartialRotater类中的优化策略,支持OTG(OpenDocument图形模板),下面我们一起来探索新版中的新增功能及其工作原理。

  ▲IMAGINGNET-2926 - 将PSD保存到PDF中不提供可选择的文本

  //将文本转换为向量对象

  using (Image image=Image.Load("text.psd"))

  {

  image.Save(fileName + "text_vector.pdf", new PdfOptions());

  }//

  //老式的转换与充分光栅化

  using (Image image=Image.Load("text.psd", new PsdLoadOptions() { ReadOnlyMode=true }))

  {

  image.Save(fileName + "text_vector.pdf", new PdfOptions());

  }

  ▲IMAGINGNET-3381 - 在PartialRotater类中支持优化策略

  //为目标加载的图像设置50兆字节的内存限制

  using (var image=Image.Load(imageFilePath, new LoadOptions() { BufferSizeHint=50 })) {

  //执行RotateFlip操作

  image.RotateFlip(RotateFlipType.Rotate90FlipNone);

  //执行旋转操作

  ((RasterImage)image).Rotate(60); // rotate 60 degrees clockwise

  }

  ▲IMAGINGNET-2044 - 支持OTG (OpenDocument图形模板)

  string baseFolder="D:";

  string fileName="VariousObjectsMultiPage.otg";

  ImageOptionsBase[] options={ new PngOptions(), new PdfOptions() };

  foreach (ImageOptionsBase item in options)

  {

  string inputFileName=Pathbine(baseFolder, fileName);

  string fileExt=item is PngOptions ? ".png" : ".pdf";

  string outputFileName=Pathbine(baseFolder, fileName + fileExt);

  using (Image image=Image.Load(inputFileName))

  {

  OtgRasterizationOptions otgRasterizationOptions=new OtgRasterizationOptions();

  otgRasterizationOptions.PageSize=image.Size;

  item.VectorRasterizationOptions=otgRasterizationOptions;

  image.Save(outputFileName, item);

  }

  }

  ▲IMAGINGNET-3442 - Bpmn SVG转换导致陌生的PNG

  using(Image image=Image.Load(“input.svg”))

  {

  image.Save(

  “output.png”,

  new PngOptions()

  {

  VectorRasterizationOptions=new SvgRasterizationOptions

  {

  PageSize=image.Size,

  }

  });

  }

  ▲IMAGINGNET-3430 - 支持PDFOptions中的DPI设置

  string baseFolder=“D:

  ”;

  string fileName=“standardSize.tif”;

  string inputFileName=Pathbine(baseFolder,fileName);

  string outFileName=inputFileName +“。pdf”;

  using(Image image=Image.Load(inputFileName))

  {

  PdfOptions pdfOptions=new PdfOptions {PageSize=new SizeF(612,792 )};

  image.Save(outFileName,pdfOptions);

  }

  ▲IMAGINGNET-3286 - 没有从WMF到SVG的真正转换

  string baseFolder=Pathbine("D:","3286");

  string fileName="image2.wmf";

  string inputFileName=Pathbine(baseFolder, fileName);

  using (Image image=Image.Load(inputFileName))

  {

  string script=((WmfImage)image).GetPostScript();

  string ethlonScript=File.ReadAllText(inputFileName + ".ps");

  if (script !=ethlonScript)

  {

  throw new Exception("script not eqal ethalon script");

  }

  }

  Since PostScript is not supported in Aspose products, further processing is done by **third-party applications**.

  For example:

  Use ghostscript (ghostscript/)

  string baseFolder=Pathbine("D:","3286");

  string fileName="image2.wmf";

  string inputFileName=Pathbine(baseFolder, fileName);

  string scriptFileName=inputFileName + ".ps";

  string outputPdfFileName=scriptFileName + ".pdf";

  string ghostPath="C:

  Program Files (x86)

  gs

  gs8.61

  bin

  gswin32c.exe";

  string script;

  using (Image image=Image.Load(inputFileName))

  {

  script=((WmfImage)image).GetPostScript();

  }

  File.WriteAllText(scriptFileName, script);

  string cmdArguments=string.Format(" -sDEVICE=pdfwrite -o {0} {1}", outputPdfFileName, scriptFileName);

  Process proc=System.Diagnosticscess.Start(ghostPath, cmdArguments);

  proc.WaitForExit(60000);

  ▲IMAGINGNET-3230 - 将Jpeg转换为Tiff会导致绿色覆盖不正确

  using(Image image=Image.Load(“input.jpg”))

  {

  image.Save(“output.tiff”,new TiffOptions(TiffExpectedFormat.TiffJpegRgb));

  }

  ▲IMAGINGNET-3445 - 来自font文件夹的文件被锁定

  string baseFolder=Pathbine("D:", "test");

  string fontsFolder=Pathbine(baseFolder, "fonts");

  //创建字体文件夹

  if (!Directory.Exists(fontsFolder))

  {

  Directory.CreateDirectory(fontsFolder);

  }//

  //复制字体到字体文件夹

  string fontFile=Pathbine(fontsFolder, "foo.ttf");

  if (!File.Exists(fontFile))

  {

  File.Copy(Pathbine(baseFolder, "foo.ttf"), fontFile);

  }//

  //设置字体路径

  List fonts=new List(FontSettings.GetDefaultFontsFolders());

  fonts.Add(fontsFolder);

  FontSettings.SetFontsFolders(fonts.ToArray(), true);//

  //打开图片

  string inputFile=Pathbine(baseFolder, "grinched-regular-font.psd");

  string outputFile=inputFile + ".png";

  using (Image image=Image.Load(inputFile))

  {

  PngOptions saveOptions=new PngOptions();

  image.Save(outputFile, saveOptions);

  }

  //删除字体文件夹

  Directory.Delete(fontsFolder,true);

  ▲IMAGINGNET-3444 - 用于调整SVG图像大小的Aspose.Imaging问题

  string baseFolder="D:

  ";

  string inputFileName=Pathbine(baseFolder, "logotype.svg");

  float scale=10f;

  using (Image image=Image.Load(inputFileName))

  {

  image.Save(inputFileName+".png", new PngOptions()

  {

  VectorRasterizationOptions=new SvgRasterizationOptions()

  {PageSize=image.Size, ScaleX=scale, ScaleY=scale}

  });

  }

posted @ 2022-02-16 15:48  ebuybay  阅读(794)  评论(0编辑  收藏  举报